我正在尝试使用AddressBook框架向现有联系人添加电话号码,在选择具有选择器的人员后调用此方法:
- (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;
}
但在此之后,该号码不会添加到此人的记录中。我做错了什么?
答案 0 :(得分:4)
您需要将此记录保存到地址簿中。
使用addressBook
的{{1}}属性获取地址簿,然后拨打ABPeoplePickerNavigationController
。
这给你类似的东西:
ABAddressBookSave
您可以测试- (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;
}
成功/失败的返回值,并在ABAddressBookSave
变量中获取其他信息。