Skip to content

Instantly share code, notes, and snippets.

@troZee
Created October 9, 2017 14:22
Show Gist options
  • Save troZee/24f3280b967d892809efb3e732608974 to your computer and use it in GitHub Desktop.
Save troZee/24f3280b967d892809efb3e732608974 to your computer and use it in GitHub Desktop.
// this func show CNContactViewController for new contact and fill it using CNMutableContact
// Remember about permissions
func createContcat() {
if #available(iOS 9.0, *) {
let contact = CNMutableContact()
contact.givenName = "Jack"
contact.familyName = "Sparrow"
contact.emailAddresses = [CNLabeledValue(label: CNLabelHome, value: NSString(string: "p@p.pl")),CNLabeledValue(label: CNLabelHome, value: NSString(string: "p@p.pl")),CNLabeledValue(label: CNLabelHome, value: NSString(string: "p@p.pl")),CNLabeledValue(label: CNLabelHome, value: NSString(string: "p@p.pl"))]
let store = CNContactStore()
let controller = CNContactViewController(forNewContact: contact)
controller.contactStore = store
controller.delegate = self
let navigationController = UINavigationController(rootViewController: controller)
self.present(navigationController, animated: true, completion: nil)
// let saveRequest = CNSaveRequest()
// If you want to save this contact programmatically
// saveRequest.add(contact, toContainerWithIdentifier: nil)
// do {
// try store.execute(saveRequest)
// } catch {
// print("Something went wrong!")
// }
}
}
//For more
// https://developer.apple.com/documentation/contacts
// https://developer.apple.com/documentation/contactsui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment