0
votes

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
Did you read the Address Book Programming Guide for iPhone OS?zoul
Ya I read it, But I am not able use ABAddressBook class to access the addressbook database, If you have any sample code plz post it.CKT

1 Answers

4
votes

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.