How to create a contact in the “local” addressbook?

南楼画角 提交于 2019-12-11 10:01:01

问题


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


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/4675756/how-to-create-a-contact-in-the-local-addressbook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!