Accessing native iPhone addressbook database and performing add and delete contacts?
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, a开发者_开发问答nd.. how to add and delete contacts from the address book? Can anyone post the sample code for this?
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.
精彩评论