7
我嘗試使用聯繫人框架創建並保存組。 首先,用戶授權應用程序進行聯繫人訪問。 提供了一個視圖控制器,並帶有一個+按鈕用戶顯示帶有文本框的警報視圖。使用聯繫人框架創建新組,CNErrorDomain代碼= 2
用戶鍵入他想要的組名稱,然後單擊按鈕來保存alertview(save)。
這是保存新組的代碼。組名稱是有,但它不可能仍要保存這組:
CNContactStore *contactStore = [CNContactStore new];
[contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError *error){
if (granted) {
CNMutableGroup *newGroup = [CNMutableGroup new];
CNSaveRequest *saveRequest = [CNSaveRequest new];
[newGroup setName:groupName];
//when saving to container with identifier nil, we get this error:
//Error Domain=CNErrorDomain Code=2 "(null)" UserInfo={CNInvalidRecords=(
//"<CNMutableGroup: 0x10a059f20: identifier=2F4981B9-8A47-45A4-8841-1FA5A09584A4:ABGroup, name=gghh>"
[saveRequest addGroup:newGroup toContainerWithIdentifier:nil];
[contactStore executeSaveRequest:saveRequest error:&error];
if (error){
//error saving group
//NSLog(@"error message: %@",error);
} else {
//if no errors, reload tableview
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
}
}];
Error Domain=CNErrorDomain Code=2 "(null)" UserInfo={CNInvalidRecords=(
"<CNMutableGroup: 0x14fb3e5e0: identifier=8E490585-1223-407E-B353-0D25609B05AB:ABGroup, name=jddjd>"
)}
下一個奇怪的是:爲什麼是保存請求試圖挽救這組
標識符爲:ABGroup
末?
該錯誤包含有關CNInvalidRecords
的信息。
我只使用聯繫人框架。
這是怎麼發生的?
任何解決方案?
這造成如果一個新的羣體,提供的iCloud設置爲默認設置>郵件,日曆,聯繫人。如果默認爲Exchange,則無法創建和保存組。這就是爲什麼我得到這個錯誤。我正在尋找解決此問題的解決方法。 – brush51
根據Apple的文檔,您無法在Exchange容器中創建組,您需要爲每個「組」創建一個單獨的容器。 –
是的,這是正確的,但我想這將不可能創建另一個獨立的容器來創建一個新的組,並在本地保存當iCloud同步激活。 – brush51