From http://www.iphonedevsdk.com/forum/iphone-sdk-development/12496-add-contact-address-book.html
ABRecordRef aRecord = ABPersonCreate();
CFErrorRef anError = NULL;
ABRecordSetValue(aRecord, kABPersonFirstNameProperty,
CFSTR("Jijo"), &anError);
ABRecordSetValue(aRecord, kABPersonLastNameProperty,
CFSTR("Pulikkottil"), &anError);
if (anError != NULL) {
NSLog(@"error while creating..");
}
CFStringRef firstName, lastName;
firstName = ABRecordCopyValue(aRecord, kABPersonFirstNameProperty);
lastName = ABRecordCopyValue(aRecord, kABPersonLastNameProperty);
ABAddressBookRef addressBook;
CFErrorRef error = NULL;
addressBook = ABAddressBookCreate();
BOOL isAdded = ABAddressBookAddRecord (
addressBook,
aRecord,
&error
);
if(isAdded){
NSLog(@"added..");
}
if (error != NULL) {
NSLog(@"ABAddressBookAddRecord %@", error);
}
error = NULL;
BOOL isSaved = ABAddressBookSave (
addressBook,
&error
);
if(isSaved){
NSLog(@"saved..");
}
if (error != NULL) {
NSLog(@"ABAddressBookSave %@", error);
}
CFRelease(aRecord);
CFRelease(firstName);
CFRelease(lastName);
CFRelease(addressBook);
If you need to store data in there, I think your only option is kABPersonNoteProperty
, but I'm no expert on this.
Edit: http://stackoverflow.com/questions/1418319/does-iphone-support-adding-custom-properties-to-address-book-records
Answer: nope!
Edit: you can also prompt the user to add an address book entry as done here http://stackoverflow.com/questions/1041410/how-to-get-around-lack-of-add-button-in-abpeoplepickernavigationcontroller