2

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

enter image description here

narner
  • 2,908
  • 3
  • 26
  • 63

2 Answers2

1

Instead of creating a UINavigationController instance, try presenting the contact controller directly.

[self presentViewController:contactController animated:YES completion:nil];

CNContactViewControllerDelegate

- (void)contactViewController:(CNContactViewController *)viewController 
   didCompleteWithContact:(CNContact *)contact;

Present on the main thread

dispatch_async(dispatch_get_main_queue(), ^{
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:contactController];
    navController.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentViewController:navController animated:YES completion:nil];
});
WrightsCS
  • 50,551
  • 22
  • 134
  • 186
  • I had actually tried that before creating a `UINavigationController` instance, but would get a repeated error log of: `[CNUI ERROR] Contact view delayed appearance timed out` – narner Nov 12 '16 at 18:46
  • 1
    Have you implemented the `CNContactViewControllerDelegate`? – WrightsCS Nov 12 '16 at 18:48
  • I hadn't implemented that method; thank you - I made an edit to the question with what I added; still getting the same log error. – narner Nov 12 '16 at 18:55
  • In https://stackoverflow.com/questions/38748969/cnui-error-contact-view-delayed-appearance-timed-out a comment says this error was new to iOS SDK 10, hence the need to put it in a `UINavigationController`. – benc Mar 20 '20 at 02:46
0

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];
narner
  • 2,908
  • 3
  • 26
  • 63