i try to create and save a group with the Contacts Framework. First the user authorize the App for contacts access. A viewcontroller is presented and with a + button user shows an alertview with textfield.
The user types the group name he wants and click to button of the alertview (save).
This is the code for saving the new group. The group name is available but it is not possible to save this group anyway:
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>"
)}
The next strange thing is: why is the save request trying to save this group
with identifier :ABGroup
at the end?
The Error contains a info about CNInvalidRecords
.
I am only using the Contacts Framework.
Why is this happening?
Any solutions for that?