开发者

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜