How to save a contact to iOS address book with an image?


#1

How can I use the contacts plugin to save a contact that contains an image on iOS? It doesn’t seem like there’s any documentation on this. I know that contact images are retrieved through the temporary storage on the device, but I don’t know how to export those images or how to save normal images to that format.


#2

You should combine two ngCordova plugins.

The first one is image picker: http://ngcordova.com/docs/plugins/imagePicker/ which you can use to select an image (just limit it to one selection).

When you find a URI just use it in a ngCordova contacts plugin. Here’s a tutorial on how to do that, it also includes a working example with an image.


#3

Awesome, thanks. Followup question: for the life of me I cannot figure out how to export a retrieved contact image (see this post). How can I do this on iOS and Android?


#4

Look at my other article: http://www.gajotres.net/accessing-image-galery-using-ionic-and-ngcordova/

You’ll find an example how to convert an image to BASE64 encoding using this Cordova plugin: https://github.com/hazemhagrass/phonegap-base64


#5

Thanks, but that article is about accessing the stored images on your phone. I’m talking about accessing the image of an imported contact. I tried this:

window.plugins.Base64.encodeFile(contact.photos[0].value, function(base64){
    console.log('file base64 encoding: ' + base64);
});

Prepending file:/// to contact.photos[0].value didn’t work either. On iOS, an example of a returned image URL is:

/Users/jack/Library/Developer/CoreSimulator/Devices/52BFF15A-4B38-4985-8398-1DA239EC8397/data/Containers/Data/Application/8B47FEEF-8CBE-43BF-B602-FDB46B952FCC/tmp/photo_GgPaN


#6

Okay, I found the issue. The simulator was restricting access to file URLs. The plugin works perfectly on iOS devices.