Add phone number to existing contact

为君一笑 提交于 2019-12-04 17:14:26

You need to save this record to the address book.

Get the address book using the addressBook property of ABPeoplePickerNavigationController, then call ABAddressBookSave.

This gives you something like:

- (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); 

        ABAddressBookRef ab = peoplePicker.addressBook;
        CFErrorRef* error = NULL;
        ABAddressBookSave(ab, error);
        CFRelease(multiPhone);
    }

    return FALSE;
}

You can test ABAddressBookSave return value for success / failure, and get additional information in error variable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!