With ABAddressBook, when I wanted the user to be able to have the options of "Create New Contact" and "Add to Existing Contact" for a contact they hadn't seen before, I would create and present an ABUnknownPersonViewController
.
I can find no way to replicate this functionality in the CNContacts framework. It seemed to me that CNContactViewController(forUnknownContact: contact)
could work, but unfortunately this only lets the user "Send Message" or "Share Contact."
How can I allow a user to save the contact to their address book, either as a new contact or as part of an existing one, in CNContacts?
func presentContact() {
let status = CNContactStore.authorizationStatusForEntityType(.Contacts)
switch status {
case .Authorized: ()
case .NotDetermined: requestAccess()
case .Denied, .Restricted: accessDenied()
}
print("authorized? \(status == .Authorized)") //prints "authorized? true"
let unknown = CNContactViewController(forUnknownContact: contact!)
unknown.delegate = self
self.navigationController?.pushViewController(unknown, animated: false)
}
Even when I try to request access, the user still can't save the contact.