-5

I have a "+" button in my app, and when I tapped, I want to navigate to the "new contact" screen (like the image below).

enter image description here

I have found the same question here: iOS - add contact into Contacts? but the code is not up to date. I want a solution in Swift 5.

Alex Giatrakis
  • 365
  • 3
  • 16

1 Answers1

2
import Contacts      // import these framework
import ContactsUI

//--- Your Button Action
@IBAction func buttonClick(_ sender: Any)
{
    let openContact = CNContact()
    let vc = CNContactViewController(forNewContact: openContact)
     vc.delegate = self // this delegate CNContactViewControllerDelegate
   // self.navigationController?.pushViewController(vc, animated: true)
   self.present(UINavigationController(rootViewController: vc), animated:true)
}


func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) {

    self.dismiss(animated: true, completion: nil)
}
Lalit kumar
  • 1,797
  • 1
  • 8
  • 14