Created
October 9, 2017 14:22
-
-
Save troZee/24f3280b967d892809efb3e732608974 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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