Accessing native iPhone addressbook database and performing add and delete contacts?

余生长醉 提交于 2020-01-01 19:55:10

问题


In my application I need to implement the address book which should contains the native addressbook details, and the user should be able to add and delete from the address book and it should be updated in the native iphone addressbook.

I read somewhere that the iphone native address book database is accesible. In documentation also I saw that addContact and Delete API's are exposed to addressbook.

Can anyone please tell me how can I access the native AddressBook of the iphone, and.. how to add and delete contacts from the address book? Can anyone post the sample code for this?


回答1:


You need to use ABRecords and ABAddressBook. For example, adding can be done:

#import <AddressBook/AddressBook.h>

...

ABRecordRef record = ABPersonCreate();
ABAddressBookRef addressBook = ABAddressBookCreate();

ABRecordSetValue(record, kABPersonFirstNameProperty, CFSTR("Kevin"), NULL);
ABRecordSetValue(record, kABPersonLastNameProperty, CFSTR("Sylvestre"), NULL); 

ABAddressBookAddRecord(addressBook, record, NULL);

ABAddressBookSave(addressBook, NULL);

It is important that you add the AddressBook.Framework to your project (right click on 'Frameworks' > 'Add' > 'Existing Frameworks'). The documentation should give you enough to figure out how to remove, etc.



来源:https://stackoverflow.com/questions/2582976/accessing-native-iphone-addressbook-database-and-performing-add-and-delete-conta

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