I searched now for at least 2 hours and couldn't find an answer for this.
I need to have an object of type CNContact
. I found the CNContactViewController
and this view would meet perfectly my requirements. With it I can create a new contact with the predefined view and this gives me an CNContact
object.
This is my problem:
The CNContactViewController
saves the created contact to the contactStore
. But I don't want this. Can I suppress this behaviour? I'm pretty sure there must be a solution.
This is my code for creation of the ViewController
:
let contactController = CNContactViewController(forNewContact: nil)
contactController.allowsEditing = true
contactController.allowsActions = false
contactController.displayedPropertyKeys = [CNContactPostalAddressesKey, CNContactPhoneNumbersKey, CNContactGivenNameKey]
contactController.delegate = self
contactController.view.layoutIfNeeded()
let navigationController = UINavigationController(rootViewController: contactController)
self.present(navigationController, animated: true)
Here I would like to use the contact without having it in the Addressbook:
func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) {
viewController.navigationController?.dismiss(animated: true)
}
Thanks for your help!