【问题标题】:CNContactVCardSerialization.dataWithContacts giving exceptionCNContactVCardSerialization.dataWithContacts 给出异常
【发布时间】:2016-07-25 08:13:35
【问题描述】:

我正在尝试使用方法CNContactVCardSerialization.dataWithContacts() 将 CNContact 数组转换为 vCard。但它给了我以下错误。

2016-07-25 14:05:00.115 AddressBook-ios9[902:28918] Exception writing contacts to vCard (data): A property was not requested when contact was fetched.

我确保我传递了一个有效的 CNContacts 数组,但它仍然给出了这个异常。谁能指导我做错了什么?

我在下面附上源代码。

func getVcardFromSearchingName(name: String) -> NSData? {
    do {            
        if let contacts = searchMultiContacts(name) {
            print(contacts)
            let vCard = try CNContactVCardSerialization.dataWithContacts(contacts)
            return vCard
        } else {
            return nil
        }
    } catch {
        return nil
    }
}

【问题讨论】:

    标签: ios swift vcf-vcard cncontact


    【解决方案1】:

    我发现了我的错误。在获取联系人的键上,我错过了CNContactVCardSerialization.descriptorForRequiredKeys()。添加后,代码运行正常。

    【讨论】:

    • #haider_kazal : 你能告诉我如何使用上面的 CNContactVCardSerialization.descriptorForRequiredKeys()
    • @AbhishekThapliThapliyal... 正如我所提到的,unifiedContactsMatchingPredicate() 方法需要keysToFetch;在keysToFetch 中包含CNContactVCardSerialization.descriptorForRequiredKeys() 以获取创建VCard 所需的数据
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-23
    • 2020-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多