gpt4 book ai didi

ios - 原因 : '-[CNContact setSnapshot:]: unrecognized selector sent to instance 0x7fc84c8491c0'

转载 作者:行者123 更新时间:2023-11-28 21:26:45 25 4
gpt4 key购买 nike

当我从 iPhone 通讯录中删除联系人时,它崩溃了。下面的代码,

CNContactStore * contactStore = [[CNContactStore alloc] init];
CNContactFetchRequest * contactRequest = [[CNContactFetchRequest alloc] initWithKeysToFetch:[self contactKeys]];
[contactStore enumerateContactsWithFetchRequest:contactRequest error:&err usingBlock:^(CNContact * _Nonnull contact, BOOL * _Nonnull stop) {
if([contact.familyName isEqualToString:contactItem.familyName] &&
[contact.middleName isEqualToString:contactItem.middleName] &&
[contact.givenName isEqualToString:contactItem.givenName]) {

CNLabeledValue<CNPhoneNumber*>* number1 = [contact.phoneNumbers firstObject];
CNPhoneNumber *phone = number1.value;
NSString *number2 = [contactItem.phoneNumbers firstObject];
if ([phone.stringValue isEqualToString:number2]) {
CNSaveRequest *deleteRequest = [[CNSaveRequest alloc] init];
[deleteRequest deleteContact:(CNMutableContact *)contact];
CNContactStore *deletestore = [[CNContactStore alloc] init];
[deletestore executeSaveRequest:deleteRequest error:nil];
*stop = YES;
}
}
}];

当线程在这里运行时 [deletestore executeSaveRequest:deleteRequest error:nil]; ,它崩溃了!我真的不明白代码有什么问题~很简单的一个片段。感谢您的帮助!

最佳答案

好吧,到现在为止,没有人回答我的问题。我自己解决了。我从联系人中获取所有人,然后迭代该人。解决方案是:原代码[deleteRequest deleteContact:(CNMutableContact *)contact];更改代码后 [deleteRequest deleteContact:(CNMutableContact *)contact mutableCopy];

没关系。但我不知道为什么?

关于ios - 原因 : '-[CNContact setSnapshot:]: unrecognized selector sent to instance 0x7fc84c8491c0' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37851465/

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