ios - How to use method dataWithContacts in CNContactVCardSerialization? -


i trying nsdata object vcard representation of contact. code:

let contactstore = cncontactstore() let fetchrequest = cncontactfetchrequest(keystofetch: [cncontactgivennamekey, cncontactfamilynamekey])  var contacts = [cncontact]() var vcard = nsdata()      do{             try contactstore.enumeratecontactswithfetchrequest(fetchrequest) { (contact, status) -> void in             self.fetchrequest.unifyresults = true             self.contacts.append(contact)}      } catch {             print("error \(error)")       }       {            try vcard = cncontactvcardserialization.datawithcontacts(contacts)     } catch {           print("error \(error)")       }  

but, error:

exception writing contacts vcard (data): property not requested when contact fetched. error nilerror.

i understand error in access contacts, how fix it?

i found solution , 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 vcard representation of specified contacts  {     try vcardfromcontacts = cncontactvcardserialization.datawithcontacts(contacts) } catch {     print("vcardfromcontacts \(error)") } 

but, whet returns contacts vcard data:

do {     try contactsfromvcard = cncontactvcardserialization.contactswithdata(vcardfromcontacts) } catch {     print("contactsfromvcard \(error)") } 

field contact imagedata has nil. though not nil.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

html - Outlook 2010 Anchor (url/address/link) -

android - How to create dynamically Fragment pager adapter -