views:

134

answers:

1

Hi, In the iphone app,I've a form with details such as name,address. I need to save the name,address in the form to the iPhone AddressBook.Please someone help me how to do this.

Thanks in advance.

+1  A: 
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABPersonCreate();

CFErrorRef error;
if (!ABRecordSetValue(person, kABPersonFirstNameProperty, @"John", &error))
{
   // error
}
if (!ABRecordSetValue(person, kABPersonLastNameProperty, @"Smith", &error))
{
   // error
}
if (!ABAddressBookAddRecord(addressBook, person, &error))
{
   // error
}
if (!ABAddressBookSave(addressBook, &error))
{
   // eror
}

You can set other properties with other kABxx constants.

Marco Mustapic
Do not forget to ABAddressBookSave()
Nikolai Ruhe