[英]Add phone number to existing contact
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: 我尝试使用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;
}
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 of ABPeoplePickerNavigationController
, then call ABAddressBookSave
. 使用ABPeoplePickerNavigationController
的addressBook
属性获取地址簿,然后调用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. 您可以测试ABAddressBookSave
返回值的成功/失败,并获取error
变量中的其他信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.