CNContactVCardSerialization不断抛出错误

时间:2017-06-09 13:18:00

标签: macos vcard cncontact

我无法找到一个解决方案,因为“CNContactVCardSerialization”这一行不断引发错误。关于这里可能出现什么问题和/或如何解决问题的任何想法?使用CNContacts获取数组工作正常。

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


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

    do{
        try contactStore.enumerateContacts(with: fetchRequest, usingBlock: {
            contact, cursor in
            contacts.append(contact)})
    } catch {
        print(">>>[ERROR] Unable to get contacts: \(error)")
    }

    // Returns the vCard representation of the specified contacts
    print(">>>[INFO ] Number of contacts found: \(contacts.count)")


    do {
        try vcardFromContacts = CNContactVCardSerialization.data(with: contacts) as NSData
    } catch {
        print(">>>[ERROR] Unable to create Vcard information: \(error)")
    }

0 个答案:

没有答案