ios - How to get VCF data with contact images using CNContactVCardSerialization dataWithContacts: method? -


i'm using cncontacts , cncontactui framework , picking contact via this

cncontactpickerviewcontroller *contactpicker = [cncontactpickerviewcontroller new];               contactpicker.delegate = self;  [self presentviewcontroller:contactpicker animated:yes completion:nil]; 

and

-(void)contactpicker:(cncontactpickerviewcontroller *)picker didselectcontact:(cncontact *)contact {     nsarray *array = [[nsarray alloc] initwithobjects:contact, nil];     nserror *error;     nsdata *data = [cncontactvcardserialization datawithcontacts:array error:&error];     nslog(@"error_if_any :: %@",error.description); } 

this contact object have contact.imagedata , coming in logs. when tried cross check data by

nsarray *contactlist = [nsarray arraywitharray:[cncontactvcardserialization contactswithdata:data error:nil]]; cncontact *contactobject = [contactlist objectatindex:0]; 

this getting null //contactobject.imagedata

need why i'm getting null , contact has image when check in contacts?

as workaround can create photo field inside of vcard.

nserror* error = nil; nsdata* vcarddata = [cncontactvcardserialization datawithcontacts:@[contact] error:&error]; nsstring* vcstring = [[nsstring alloc] initwithdata:vcarddata encoding:nsutf8stringencoding]; nsstring* base64image = contact.imagedata.base64encoding; nsstring* vcardimagestring = [[@"photo;type=jpeg;encoding=base64:" stringbyappendingstring:base64image] stringbyappendingstring:@"\n"]; vcstring = [vcstring stringbyreplacingoccurrencesofstring:@"end:vcard" withstring:[vcardimagestring stringbyappendingstring:@"end:vcard"]]; vcarddata = [vcstring datausingencoding:nsutf8stringencoding]; 

for reasons cncontactvcardserialization not use photo of contact. vcard after serialization looks like:

begin:vcard version:3.0 prodid:-//apple inc.//iphone os 9.3.2//en n:contact;test;;; fn: test  contact  end:vcard 

after insertion photo field inside vcard get

begin:vcard version:3.0 prodid:-//apple inc.//iphone os 9.3.2//en n:contact;test;;; fn: test  contact  photo;type=jpeg;encoding=base64:<photo base64 string> end:vcard 

after insertion contact looks fine in cncontactviewcontroller


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -