gpt4 book ai didi

iOS:从地址簿中删除联系人时出错:[CNDataMapperContactStore executeSaveRequest:error:]

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:07:02 27 4
gpt4 key购买 nike

我正在尝试删除地址簿中的联系人,但出现以下错误。

这是我的实现:

 CNMutableContact *contact = [[cnContacts objectAtIndex:i] copy];
[cnContacts removeObjectAtIndex:i];


CNSaveRequest *request = [[CNSaveRequest alloc] init];
[request deleteContact:contact];

NSError *error;
if (![self.ContactStore executeSaveRequest:request error:&error]) {
if (error)
{
NSLog(@"error = %@", error.description);
}
}

在这一行:

if (![self.ContactStore executeSaveRequest:request error:&error]) {

我在控制台中收到此错误:

-[CNContact setSnapshot:]: 无法识别的选择器发送到实例 0x145de3940

还显示此错误:

Contacts`-[CNDataMapperContactStore executeSaveRequest:error:]:
libdispatch.dylib`_dispatch_mgr_thread:

enter image description here enter image description here

你们中的任何人都知道为什么会出现此错误或我在实现过程中做错了什么。

最佳答案

我不知道这个 API,但环顾四周我看到了:

[request deleteContact:contact];

需要一个 CNMutableContact 对象,并且您已使用 copy 使其不可变:

 CNMutableContact *contact = [[cnContacts objectAtIndex:i] copy];
// contact is actually a CNContact object

你想要 mutableCopy,但是我认为根本不需要创建副本,假设 cnContacts 包含 CNMutableContact 实例,因为从数组中删除它不会破坏对象,因为您仍然在本地引用它。

我只能假设 snapshotCNMutableContact 的私有(private)属性,它在 CNContact 上不可用,因此无法识别的选择器 异常(我在类引用中看不到任何有关此属性的信息)。

关于iOS:从地址簿中删除联系人时出错:[CNDataMapperContactStore executeSaveRequest:error:],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36628013/

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