我正在尝试使用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 } }I'm trying to convert a CNContact array to vCard using the method CNContactVCardSerialization.dataWithContacts(). But it is giving me the following error.
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.
I made sure that I'm passing an valid array of CNContacts, but still it is giving this exception. Can anybody guide to me to what I've done wrong?
I'm attaching the source code below.
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 } }最满意答案
我发现了我的错误。 在获取联系人的键上,我错过了CNContactVCardSerialization.descriptorForRequiredKeys() 。 添加后,代码运行完美。
I found out my mistake. On the keys to fetch contact, I was missing CNContactVCardSerialization.descriptorForRequiredKeys(). After adding it, the code is working flawlessly.
更多推荐
发布评论