0

How to get a callBack when user successfully saves or dismiss the CNContactViewController

func addContact(contactDetails: ContactDetails) {
    let store = CNContactStore()
    let contact = CNMutableContact()
    let comp = contactDetails.name.components(separatedBy: " ")
    contact.givenName = comp.first ?? ""
    contact.familyName = comp.count > 1 ? comp[1] : ""
    let homePhone = CNLabeledValue(label: CNLabelHome, value: CNPhoneNumber(stringValue :contactDetails.phone ))
    contact.phoneNumbers = [homePhone]
    let workEmail = CNLabeledValue(label:CNLabelWork, value:contactDetails.email as NSString)
    contact.emailAddresses = [workEmail]
    let controller = CNContactViewController(forUnknownContact : contact)// .viewControllerForUnknownContact(contact)
    controller.contactStore = store
    controller.delegate = self
    //self.navigationController?.setNavigationBarHidden(false, animated: true)
    self.navigationController?.pushViewController(controller, animated: true)
}
Nitesh
  • 1,564
  • 2
  • 26
  • 53

1 Answers1

0

You can declare a delegate / protocol for communicate between controllers. Check below link for simple code example;

Simple Protocol Example

Emre Önder
  • 2,408
  • 2
  • 23
  • 73
  • But how I can do it in this scenario as this is done on `CNContactViewController` – Nitesh Nov 14 '17 at 15:02
  • Create a protocol function in your firstViewController. Then in your contactViewController call this function where you tap dismiss button etc.. – Emre Önder Nov 15 '17 at 11:31