Swift 3 adds new contact with phone and email

I am trying to suggest the user to create a new contact and pass on the information. (in particular telephone and email)

I found many examples of using CNMutableContact and adding email to it. However, any code containing CNContact gives me the error "Using an undeclared type."

How to set up my class to suggest the user to keep the contact?

+7
ios xcode swift swift3 contacts
source share
2 answers
func addPhoneNumber(phNo : String) { if #available(iOS 9.0, *) { let store = CNContactStore() let contact = CNMutableContact() let homePhone = CNLabeledValue(label: CNLabelHome, value: CNPhoneNumber(stringValue :phNo )) contact.phoneNumbers = [homePhone] let controller = CNContactViewController(forUnknownContact : contact) controller.contactStore = store controller.delegate = self self.navigationController?.setNavigationBarHidden(false, animated: true) self.navigationController!.pushViewController(controller, animated: true) } } 
+7
source share

You can do something like this.

 extension ViewController: CNContactViewControllerDelegate { func showNewContactViewController() { let contactViewController: CNContactViewController = CNContactViewController(forNewContact: nil) contactViewController.contactStore = CNContactStore() contactViewController.delegate = self let navigationController: UINavigationController = UINavigationController(rootViewController: contactViewController) present(navigationController, animated: false) { print("Present") } } } 
+1
source share

All Articles