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
Post a Comment