Search code examples
javascriptimageionic-frameworkionic3cordova-plugins

Ionic imagePicker is not opening gallery


I am trying to use the following Ionic plugin so that I can open the gallery and choose multiple images: https://ionicframework.com/docs/native/image-picker#installation

The problem that I'm facing is that when I tap the button to see "My Photos" I just get nothing come up.

In order to install I started by running the following, which is part of the installation of the plugin in docs:

ionic cordova plugin add cordova-plugin-telerik-imagepicker
npm install @ionic-native/image-picker

At this point, I have the following code to run the image picker:

HTML

<button ion-button full round (tap)="openImagePicker()">My Photos</button>      

TS

import { Camera, CameraOptions } from '@ionic-native/camera';
import { ImagePicker } from '@ionic-native/image-picker/ngx';

...

  constructor(
    ...
    private camera: Camera, 
    private imagePicker: ImagePicker,
  ) {

...

  openImagePicker(){
    let options= {
      maximumImagesCount: 5,
    }
    var photos = [];
    this.imagePicker.getPictures(options)
    .then((results) => {
      console.log(results);
    }, (err) => { console.log(err) });
  }

Solution

  • Nothing wrong with your code. As your app is Ionic V3 you should use below commands to install the plugin and node module.

    ionic cordova plugin add cordova-plugin-telerik-imagepicker --variable PHOTO_LIBRARY_USAGE_DESCRIPTION="your usage message"
    
    npm install --save @ionic-native/image-picker@4
    

    Docs