22

I am trying to show the Contacts add new contact view with the ContactsUI framework in iOS 10. The code that I am using to present CNContactViewController the is the following:

    let contactViewController = CNContactViewController(forNewContact: contact)
    contactViewController.contactStore = CNContactStore()
    contactViewController.delegate = self

    self.present(contactViewController, animated: false) {}

But every time I execute the code the app gets frozen and I get three + times the following error log: [CNUI ERROR] Contact view delayed appearance timed out

Any explanation is welcome,

dandan78
  • 13,328
  • 13
  • 64
  • 78
rockdaswift
  • 9,613
  • 5
  • 40
  • 46

1 Answers1

38

I find a workaround. Just wrap your CNContactViewController in UINavigationController and all will be fine.

Special code sample for @JackRobson

let contactViewController = CNContactViewController(forNewContact: contact)
contactViewController.contactStore = CNContactStore()
contactViewController.delegate = self
let navigationController = UINavigationController(rootViewController: contactViewController)
self.present(navigationController, animated: false) {}
Andrew Vyazovoy
  • 580
  • 4
  • 12
  • Yes! just works with let contactsNavigationController = UINavigationController(rootViewController: contactViewController) – rockdaswift Sep 20 '16 at 14:25
  • Could you show the full code exert. I'm struggling to get this to work. – Jack Robson Feb 13 '17 at 18:10
  • This works, I believe it’s a bug that was introduced with the iOS 10 SDK. – johnnieb Mar 06 '17 at 21:08
  • 1
    Well, It doesn't work anymore on iPhone X since the Cancel and OK button are at the notch level, behind the clock and network indicator... a tap on it doesn't do anything. EDIT : It works with the self.present(). I tried with navigationController.pushViewController() – zarghol Nov 16 '17 at 15:17
  • Is your notch problem occurring only with the `CNContactViewController`, but not happening with the VC that is below it? – benc Aug 05 '19 at 20:16
  • 1
    When I achieve to show the "CNContactViewController" from my table view "didSelectRowAt indexPath" HOW DO I GET BACK???? There is no way to get back to the previous screen (my TableView) – Markus Aug 19 '19 at 21:59
  • SOLVED!!!! -> https://stackoverflow.com/questions/37390406/unable-to-dismiss-cncontactviewcontroller – Markus Aug 19 '19 at 22:06
  • If the operation is called by a modal presented ViewController I didn't find a way to dismiss. – Andrea Leganza Dec 29 '20 at 11:18
  • Yeah, basically you have to implement the delegate's contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) function. It will tell you once they save the contact, so you can dismiss the screen. Agreed on the fact you can't do anything on the screen if you use a full screen modal - use a nav controller, and you're good to go. – wildcat12 Apr 01 '22 at 19:46