2016-04-14 65 views
2

我試圖在地址簿中刪除聯繫人,但出現以下錯誤。iOS:從地址簿中刪除聯繫人時出錯:[CNDataMapperContactStore executeSaveRequest:error:]

這是我實現:

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

任何的你知道爲什麼這個錯誤還是什麼,我做錯了,我實現。

回答

1

我不知道這個API,但環顧四周我看到:

[request deleteContact:contact]; 

需要CNMutableContact對象,你讓一成不變的使用copy

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

你想mutableCopy ,但是我根本沒有看到需要創建副本,假設cnContacts包含CNMutableContact實例,因爲從陣列中刪除它不會破壞該對象,因爲您仍然有對它的引用。凱莉。

我只能假設snapshotCNMutableContact私有財產是不提供CNContact,因此無法識別的選擇異常(我認爲沒有這個屬性的類的引用)。

+0

mutableCopy訣竅。謝謝! – user2924482

相關問題