I am trying to add a phone number to an existing contact using the AddressBook framework, after selecting a person with the picker this method is called:
- (BOOL) peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
if(_phoneNumber != nil)
{
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutableCopy (ABRecordCopyValue(person, kABPersonPhoneProperty));
ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)_phoneNumber, kABPersonPhoneOtherFAXLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, multiPhone,nil);
CFRelease(multiPhone);
}
return FALSE;
}
But after this the number is not added to the person's record. What am I doing wrong?
You need to save this record to the address book.
Get the address book using the
addressBook
property ofABPeoplePickerNavigationController
, then callABAddressBookSave
.This gives you something like:
You can test
ABAddressBookSave
return value for success / failure, and get additional information inerror
variable.