I am adding contact using Native CNContactViewController and once contact saved it returns contact's identifier with ':ABPerson' suffix and when I cross check in contact list same contact appears with different identifier.
Does anyone know how to get actual contact identifier?
Code to Create:
- (IBAction)didSelectedAddContact:(id)sender {
CNMutableContact *contact = [CNMutableContact new];
CNContactViewController *contactController = [CNContactViewController viewControllerForNewContact:contact];
NSLog(@"contact id : %@", contact.identifier);
contactController.allowsEditing = true;
contactController.allowsActions = true;
contactController.delegate = self;
[self.navigationController pushViewController:contactController animated:YES];
}
Delegate Callback:
- (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(nullable CNContact *)contact{
_contact = contact;
[viewController.navigationController popViewControllerAnimated:YES];
}
Below function returns nil:
- (CNContact*) getContactFromStoreForIdentifier:(NSString*) identifier
{
CNContact *updatedContact = nil;
id descriptor = [CNContactViewController descriptorForRequiredKeys];
CNContactStore *store = [CNContactStore new];
NSError *error;
updatedContact = [store unifiedContactWithIdentifier:identifier
keysToFetch:@[descriptor]
error:&error];
// Found?
if (updatedContact == nil)
{
if (error != nil)
{
}
}
return updatedContact; }
@Parameter: Identifier of CNContact object received from didCompleteWithContact: delegate callback.