How to save a contact photo with Ionic contacts?

Hello guys,

I’m trying to make an app that imports contacts, who are stored on a remote server, to the phone.
These contacts have base64 thumbnail pictures on the server, but I can’t seem to save the pictures.
I’m using the following code to check if the user has a photo or not and if contact.photos is initialized. after that I push a contactfield with the base64-type and the photo in base64.
the console.log(contact) outputs the contact with the picture, but after using the save method from Ionic native contact the logs say that contact.photos is null.

var contact = Contacts.create();
/*
    some code to fill in the other contactdetails.
*/


if (user.photo !== undefined && user.photo !== null) {
  if (!contact.photos) {
    contact.photos = [];
  }
  var cf = new ContactField('base64', user.photo);
  contact.photos.push(cf);
  console.log(contact);
  contact.save();

Any Ideas on how to fix this?

Also tried using the url of an excisting contact photo but that has the same problem…
var cf = new ContactField(‘url’, ’ content://com.android.contacts/contacts/9291/photo’);

I can not save phone number, have working code for this?

Thanks

I think this should work.

createContact() {
 var contact = Contacts.create();
 contact.phoneNumbers = [];
 var cf = new ContactField('Mobile', '0476392554');
 contact.phoneNumbers.push(cf);
 return contact;
}

Thank you, for new version you should use (< any> contact).phoneNumbers for bug at ES6

Haven’t had any issue with this code so far, what changed?

I had an error as can not assign left hand side and solved with (< any> contact).phoneNumbers