Search code examples
iphonecontactsaddressbookabaddressbook

How to create a contact in the "local" addressbook?


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


Solution

  • 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.