In my iPhone app, I want to save the vCards into my iPhone's Contacts when I click onto the vCard which I have.
How can I do that?
I have seen an app on app store which does this:
http://itunes.apple.com/us/app/read-vcard/id402216831?mt=8
Thanks
You can import or export a virtual card, called a vCard. vCards contain contact information for one or more contacts.
New Contacts Framework introduced with iOS9, saving vCard data into iPhone's contacts is much easier and simpler with Swift4.
import Contacts
func saveVCardContacts (vCard : Data) { // assuming you have alreade permission to acces contacts
if #available(iOS 9.0, *) {
let contactStore = CNContactStore()
do {
let saveRequest = CNSaveRequest() // create saveRequests
let contacts = try CNContactVCardSerialization.contacts(with: vCard) // get contacts array from vCard
for person in contacts{
saveRequest.add(person as! CNMutableContact, toContainerWithIdentifier: nil) // add contacts to saveRequest
}
try contactStore.execute(saveRequest) // save to contacts
} catch {
print("Unable to show the new contact") // something went wrong
}
}else{
print("CNContact not supported.") //
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With