CNContactVCardSerialization.dataWithContacts给出异常(CNContactVCardSerialization.dataWithContacts giving

编程入门 行业动态 更新时间:2024-10-26 06:37:03
CNContactVCardSerialization.dataWithContacts给出异常(CNContactVCardSerialization.dataWithContacts giving exception)

我正在尝试使用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.

更多推荐

本文发布于:2023-07-24 19:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1250202.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   dataWithContacts   CNContactVCardSerialization   giving   exception

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!