为现有联系人添加电话号码 [英] Add phone number to existing contact
问题描述
我正在尝试使用AddressBook框架向现有联系人添加电话号码,在选择具有选择器的人之后调用此方法:
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.
使用 ABPeoplePickerNavigationController
的 addressBook
属性获取地址簿,然后调用 ABAddressBookSave
。
Get the address book using the addressBook
property of ABPeoplePickerNavigationController
, then call 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
返回成功/失败的值,并在错误
变量中获取其他信息。
You can test ABAddressBookSave
return value for success / failure, and get additional information in error
variable.
这篇关于为现有联系人添加电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!