1

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

Peter Johnson
  • 3,764
  • 1
  • 23
  • 27
  • hi, i just wanted to confirm.... did you want to be able to save a contact to the default contacts application? – Pavan Jan 13 '11 at 01:07
  • Not exactly, as the default addressbook may not be the Local addressbook, and I need the local one (or some other means of avoiding synch, as that kills my contact record by reformatting the email address). If I manually create a local addressbook (i.e. "On My iPhone" in the contacts group page) and save the contact there, my app works great, but I'd like to make this transparent to the user. – Peter Johnson Jan 13 '11 at 13:06
  • ...on the other hand, if your question was "did I want the contact to be saved to the addressbook so it can be accessed by other apps (rather than private)?", then the answer should be "Yes". – Peter Johnson Jan 13 '11 at 18:07

2 Answers2

1

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.

Community
  • 1
  • 1
xyzzycoder
  • 1,831
  • 13
  • 19
1

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:

  1. Let's pretend you're using Gmail (Exchange)
  2. Go to your Mail settings for Gmail and disable the Contact sync
  3. When prompted whether you want to keep or remove the Gmail contacts from your phone, choose to REMOVE them (don't worry, they won't be removed from Gmail)
  4. Go back to your contacts. You can now create one LOCAL contact
  5. Finally, go back to Settings/Mail/Gmail and re-enable the Contacts sync
  6. Voila, your Gmail contacts are back into your phone and you now have 1 local contact that enables you to access the Local contacts group in addition to the Gmail contacts group.

Hope that helps (I just had the same problem and found this workaround that works great for me).

Ben.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116
Ben
  • 11
  • 1
  • 1
    Hi, yes this does work, and I have advised this method to my users, but it would be so much better to be able to do this from code. There is always a certain number of users this will trip up (and you will get occasional bad reviews, because they didn't seek any help with it) – Peter Johnson Dec 29 '11 at 16:25