I'm presenting an instance of CNContactViewController
in my app. I want the user to be able to both edit the contact, as well as to dismiss this view controller. Below is the code to present the view controller, which is embedded in a UINavigationController
. As you can see in the code, I have allowsEditing = YES
, but looking at the screenshot; you can see that I'm not able to edit. Anyone able to help me see what I'm missing? Thanks!
CNContactViewController *contactController = [CNContactViewController viewControllerForUnknownContact:contact];
contactController.allowsEditing = YES;
contactController.delegate = self;
contactController.contactStore = store;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:contactController];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navController animated:YES completion:nil];
EDIT: I tried a different method suggested by @WrightCS:
[self presentViewController:contactController animated:YES completion:nil];
And, made sure to add this delegate method:
- (void)contactViewController:(CNContactViewController *)viewController
didCompleteWithContact:(CNContact *)contact{
[self dismissViewControllerAnimated:YES completion:nil];
}
But, repeatedly get this error log:
[CNUI ERROR] Contact view delayed appearance timed out
The problem ended up being that I was initializing the CNContactViewController
incorrectly...instead of:
CNContactViewController *contactController = [CNContactViewController viewControllerForUnknownContact:contact];
Which would display a contact, but not allow for the option of cancelling out of the contact view or editing it, the correct option (for my scenario) is to use
CNContactViewController *contactController = [CNContactViewController viewControllerForNewContact:contact];