Image Picker not respecting maximumImagesCount


#1

The ionic-native plugin ImagePicker is not respecting the parameter maximumImagesCount. My desired behavior is to only allow the user to select one image but the plugin allows any number of images to be selected. Here’s my code:
addCameraImage(image:any){ let opts = { outputType: 1, maximumImagesCount: 1, quality: 65 } this.imagePicker.getPictures(opts).then((results) => { this.spinner.show("Uploading","Please wait while your image is uploaded...",true) for (var i = 0; i < results.length; i++) { this.changed = true; let base64Image = 'data:image/jpeg;base64,' + results[i]; firebase.storage().ref().child(/images/${this.authProvider.getUID()}/${this.randomString()}.jpeg).putString(results[i],'base64',{contentType:'image/jpeg'}).then(snapshot=>{ this.spinner.hide() if (!image){ this.images.push(snapshot.downloadURL) }else { let idx = this.images.indexOf(image); this.images[idx] = snapshot.downloadURL; } }); } }, (err) => { }); }

Any help is appreciated!


#2

Actually “maximumImagesCount” is not working on iOS from what i read in the release notes.
It works with older releases of the plugin, but those are causing other issues with iOS 10.

I absolutely need an imagepicker for single images too.
Maybe someone knows an alternative module with latest ios support?


#3

I realized I could use the camera plugin to select one image from the photo library. Equivalent code:
`Camera.getPicture({
quality : 60,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG,
saveToPhotoAlbum: true
}).then((imageData) => {
let loading = this.loadingCtrl.create({
spinner: “dots”,
content: ‘Please wait while your image is uploaded…’
});
loading.present();
firebase.storage().ref().child("/images/${this.authProvider.getUID()}/${this.randomString()}.jpeg").putString(imageData,‘base64’,{contentType:‘image/jpeg’}).then(snapshot=>{
loading.dismiss();
if (!image){
this.images.push(snapshot.downloadURL)
}else {
let idx = this.images.indexOf(image);
this.images[idx] = snapshot.downloadURL;
}
});

  }, (err) => {
   // Handle error
  });`