Is it possible to convert CNMutableContact
as an vCard by email ?
By below code I'm creating CNMutableContact and saving it to document directory but is it possible to send it directly instead of saving it? I don't need to save that.
let contact = CNMutableContact()
contact.givenName = "John"
contact.familyName = "Doe"
contact.emailAddresses = [
CNLabeledValue(label: CNLabelWork, value: "[email protected]")
]
let data = try! CNContactVCardSerialization.data(with: [contact])
let s = String(data: data, encoding: String.Encoding.utf8)
if let directoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first{
let fileURL = directoryURL.appendingPathComponent("john.doe").appendingPathExtension("vcf")
try! data.write(to: fileURL, options: [.atomicWrite])
}
Try Below Code for send contact as vcard in Email.