I am building an app which syncs contacts from an online source. Everything works fine so far...when the phone has one address book:
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef group1 = ABGroupCreate();
ABRecordSetValue(group1,kABGroupNameProperty,@"Group1",nil);
ABAddressBookAddRecord(addressBook,group1,nil);
ABAddressBookSave(addressBook,nil);
ABRecordRef person = ABPersonCreate();
// Edit person values...
ABGroupAddMember(group1,person,nil);
ABAddressBookAddRecord(addressBook,person,nil);
ABAddressBookSave(addressBook,nil);
CFRelease(person);
CFRelease(addressBook);
The problem occurs, however when the phone already has multiple address books. I am testing on a phone that has one address book for All Contacts, one for Gmail, etc. When I add a contact in the above manner, it adds it to the Gmail address book, and in the process strips the "Group1" identifier from the contact. Is there a way I can change the ABAddressBookRef to point to a specific address book within the phone?