2
votes

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?

2

2 Answers

0
votes

According to the reference, ABAddressBookCreate always returns an address book object populated from the system's address book database. Which means there is only ever one address book, even if you have multiple instances of ABAddressBook that you use to interact with it.

0
votes

Mike, you might want to take a look at this post: Obtaining Specific ABSource from ABAddressBook in iOS 4+

Although I believe Alex is right that there is only ever one address book, that address book may consist of multiple sources (ABSource). And, in iOS 4+ it is possible to specifically identify and manipulate particular sources.