Reputation: 3786
I am wanting to create a contact programmatically into the "local" addressbook (so that it doesn't try to synch, which causes some compatibility issues with Exchange).
If a local addressbook already exists, I can find it using ABAddressBookCopyArrayOfAllSources to get all the sources in the Address Book, then look for the ABRecordRef with a sourceTypeRef of "kABSourceTypeLocal"- if I then pass that recordRef to ABPersonCreateInSource, I can add a record to the local directory.
Does anyone have any suggestions as to how I should best go about creating a record in the "local addressBook", if there ISN'T a local addressbook already?
(also, how could I do this pre-iOS4, as the above calls weren't available then?)
Thanks
Peter
Upvotes: 1
Views: 7811
Reputation: 11
I found a simple workaround. Since you can't see/add local contacts when you don't have any pre-existing local contact, the following workaround will be safe to use:
Hope that helps (I just had the same problem and found this workaround that works great for me).
Ben.
Upvotes: 1
Reputation: 1831
You should take a look at this post: Obtaining Specific ABSource from ABAddressBook in iOS 4+
that demonstrates how to identify and target specific sources (ABSource) within the ABAddressBook. While this code mentions the function, ABGroupCreateInSource(), there is a similar function, ABPersonCreateInSource() for working with persons.
Upvotes: 1