gpt4 book ai didi

ios - 尝试更新地址簿中的标签电话号码

转载 作者:行者123 更新时间:2023-11-28 22:29:27 24 4
gpt4 key购买 nike

地址簿中存储的所有电话号码都有如下标签:“家”、“工作”、“家庭传真”等。我需要更改特定联系人的标签,放置一个名为“ATM”的自定义标签。

我收到此错误消息:

"Assertion failed: (((ABCMultiValue *)multiValue)->flags.isMutable), function ABMultiValueReplaceLabelAtIndex, file /SourceCache/AddressBook_Sim/AddressBook-796.6/ABMultiValue.c, line 118."

这是我的代码,有一条注释出现异常:

- (void)displayPerson:(ABRecordRef)person {
NSString* name = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
self.firstName.text = name;
NSString* phone = nil;
NSString* lbl = nil;
NSString* newLbl = @"ATM";

ABMultiValueRef phoneNumbers = ABRecordCopyValue(person,
kABPersonPhoneProperty);
if (ABMultiValueGetCount(phoneNumbers) > 0) {
phone = (__bridge_transfer NSString*)
ABMultiValueCopyValueAtIndex(phoneNumbers, 0);

lbl = (__bridge_transfer NSString*)
ABMultiValueCopyLabelAtIndex(phoneNumbers, 0);

//*** HERE IS THE PROBLEM ***
ABMultiValueReplaceLabelAtIndex(phoneNumbers, CFSTR("ATM"), 0);

NSLog(@" - %@ (%@)", phone, lbl);
} else {
phone = @"[None]";
lbl = @"[None]";
newLbl = @"[None]";
}

CFRelease(phoneNumbers);
}

如何更改该电话号码的标签?

最佳答案

我找到了一个解决方案:下面的代码工作正常:

- (void)displayPerson:(ABRecordRef)person

{

ABAddressBookRef ab = ABAddressBookCreate();
ABRecordRef record = ABAddressBookGetPersonWithRecordID(ab, ABRecordGetRecordID(person));
CFErrorRef *error = NULL;

ABMultiValueRef phoneNumbers = ABRecordCopyValue(record,kABPersonPhoneProperty);
ABMutableMultiValueRef phoneNumberMV = ABMultiValueCreateMutableCopy(phoneNumbers);


for(CFIndex i=0; i < ABMultiValueGetCount(phoneNumberMV); i++){
NSString *phoneNumber = (__bridge NSString *)ABMultiValueCopyValueAtIndex(phoneNumberMV,i);
//NSSlog(@"phoneNumber = %@", phoneNumber);

if ([@"1128558994" isEqualToString:phoneNumber]) {
//now delete it!!! ;-)
/*
NSSlog(@"phoneNumbers = %@",phoneNumbers);
NSSlog(@"index = %d", i);
*/

//BOOL didRemove = ABMultiValueRemoveValueAndLabelAtIndex(phoneNumberMV,i);

BOOL didChanged = ABMultiValueReplaceLabelAtIndex(phoneNumberMV, (CFStringRef)@"0870", i);
NSLog(@"didRemove = %@\n", (didChanged ? @"TRUE" : @"FALSE"));

BOOL didSet = ABRecordSetValue(record, kABPersonPhoneProperty, phoneNumberMV, nil);
NSLog(@"didSet = %@\n", (didSet ? @"TRUE" : @"FALSE"));

//and save it!
BOOL didSave = ABAddressBookSave(ab, (CFErrorRef *) error);

NSLog(@"didSave = %@\n", (didSave ? @"TRUE" : @"FALSE"));
if (error) {
NSLog(@"ABAddressBookSaveError = %@", error);
}
}
}
CFRelease(ab);

关于ios - 尝试更新地址簿中的标签电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17890841/

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