我正在尝试使用 AddressBook 框架向现有联系人添加电话号码,在使用选择器选择一个人后,此方法被调用:
- (BOOL) peoplePickerNavigationControllerABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPersonABRecordRef)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;
}
但在此之后,该号码不会添加到此人的记录中。我做错了什么?
您需要将此记录保存到通讯录中。
使用ABPeoplePickerNavigationController
的addressBook
属性获取通讯录,然后调用ABAddressBookSave
。
这会给你类似的东西:
- (BOOL) peoplePickerNavigationControllerABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPersonABRecordRef)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
返回值是否成功/失败,并在error
变量中获取更多信息。
关于objective-c - 将电话号码添加到现有联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8834379/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |