我已经获得以下代码,可以为已有电话号码的现有联系人添加额外的电话号码。然而,它在ABMultiValueAddValueAndLabel调用失败时看起来像内部地址簿断言:
断言失败:(((ABCMultiValue *)multiValue) - > flags.isMutable), 函数ABMultiValueAddValueAndLabel,file /Library/Caches/com.apple.xbs/Sources/AddressBook/AddressBook-11112.5/ABMultiValue.c, 第110行。
CFErrorRef error = nil;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);
CFArrayRef people = ABAddressBookCopyPeopleWithName(addressBook, CFSTR("SOME NAME"));
ABRecordRef person;
if ((people != nil) && (CFArrayGetCount(people) > 0))
{
// add new phone numbers to existing contact
person = CFArrayGetValueAtIndex(people, 0);
ABMutableMultiValueRef phoneNumbers = (__bridge ABMutableMultiValueRef)((__bridge NSMutableDictionary *)ABRecordCopyValue(person, kABPersonPhoneProperty));
ABMultiValueAddValueAndLabel(phoneNumbers, (__bridge CFStringRef)@"2063333333", kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumbers, nil);
ABAddressBookAddRecord(addressBook, person, nil);
但是,当调用ABMultiValueAddValueAndLabel时,创建新条目的代码非常相似:
person = ABPersonCreate();
ABRecordSetValue(person, kABPersonFirstNameProperty, @"SOME NAME", nil);
ABMutableMultiValueRef phoneNumbers = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(phoneNumbers, (__bridge CFStringRef)@"2061111111", kABPersonPhoneMainLabel, NULL);
ABMultiValueAddValueAndLabel(phoneNumbers, (__bridge CFStringRef)@"2062222222", kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumbers, nil);
ABAddressBookAddRecord(addressBook, person, nil);
为什么ABMultiValueAddValueAndLabel在第二个代码片段中成功但在第一个代码片段中失败?