【发布时间】:2015-11-05 18:33:13
【问题描述】:
我尝试使用联系人框架创建并保存一个组。 首先,用户授权应用程序访问联系人。 显示了一个视图控制器,并带有一个 + 按钮,用户显示一个带有文本字段的警报视图。
用户键入他想要的组名,然后单击警报视图的按钮(保存)。
这是保存新组的代码。群组名称可用,但无论如何无法保存此群组:
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 的信息。
我只使用联系人框架。
为什么会这样?
有什么解决办法吗?
【问题讨论】:
标签: ios ios9 cncontact cncontactstore contacts-framework