How to use method dataWithContacts in CNContactVCardSerialization?

泄露秘密 提交于 2019-12-05 19:15:54

I found the solution and it work:

let contactStore = CNContactStore()
var contacts = [CNContact]()
var vcardFromContacts = NSData()

let fetchRequest = CNContactFetchRequest(keysToFetch:[CNContactVCardSerialization.descriptorForRequiredKeys()])

do{
    try contactStore.enumerateContactsWithFetchRequest(fetchRequest, usingBlock: {
    contact, cursor in
    self.contacts.append(contact)})
} catch {
    print("Get contacts \(error)")
}

// Returns the vCard representation of the specified contacts

do {
    try vcardFromContacts = CNContactVCardSerialization.dataWithContacts(contacts)
} catch {
    print("vcardFromContacts \(error)")
}

But, whet i returns the contacts from the vCard data:

do {
    try contactsFromVcard = CNContactVCardSerialization.contactsWithData(vcardFromContacts)
} catch {
    print("contactsFromVcard \(error)")
}

field contact imageData has nil. Though it not nil.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!