gpt4 book ai didi

objective-c - 将电话号码添加到现有联系人

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:50:54 26 4
gpt4 key购买 nike

我正在尝试使用 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;
}

但在此之后,该号码不会添加到此人的记录中。我做错了什么?

最佳答案

您需要将这条记录保存到通讯录中。

使用ABPeoplePickerNavigationControlleraddressBook属性获取通讯录,然后调用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 成功/失败的返回值,并在 error 变量中获取其他信息。

关于objective-c - 将电话号码添加到现有联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8834379/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com