terikon / cordova-plugin-photo-library

Maintainer needed. Please contact if you're using this library in your project
MIT License
149 stars 295 forks source link

[plugin_not_installed] Ionic 4/5 Cordova Devapp #180

Closed chukwumaokere closed 4 years ago

chukwumaokere commented 4 years ago

I'm running Ionic 5.4.1 for testing more recently since it didn't work on 4 Ionic: 5.4.1 Cordova: 9.0.0 (cordova-lib@9.0.1) Tested on Android and iOS 13 I followed the instructions to install photolibrary, set up the privoder in app.module.ts and whenever I call the function

this.photoLibrary.requestAuthorization().then(() => {
          this.photoLibrary.getLibrary().subscribe({
            next: library => {
              library.forEach(function(libraryItem){
                console.log(libraryItem.id);          // ID of the photo
                console.log(libraryItem.photoURL);    // Cross-platform access to photo
                console.log(libraryItem.thumbnailURL);// Cross-platform access to thumbnail
                console.log(libraryItem.fileName);
                console.log(libraryItem.width);
                console.log(libraryItem.height);
                console.log(libraryItem.creationDate);
                console.log(libraryItem.latitude);
                console.log(libraryItem.longitude);
                console.log(libraryItem.albumIds);    // array of ids of appropriate Alb
              });
            },
            error: err => {console.log('could not get photos'); },
            complete: () => { console.log('done getting photos'); }
          });
        }).catch(err => console.log(err));

I get this error: ` [ng] [console.warn]: "Install the PhotoLibrary plugin: 'ionic cordova plugin add cordova-plugin-photo-library'"

` I've tried a bunch of things:

PS C:\Users\Chuck\Documents\IonicApps\conveyor> cordova plugin list
? May Cordova anonymously report usage statistics to improve the tool over time? (Y/n) Error: ENOENT: no such file or di
rectory, open 'C:\Users\Chuck\.config\configstore\cordova-config.json'
? May Cordova anonymously report usage statistics to improve the tool over time? No

You have been opted out of telemetry. To change this, run: cordova telemetry on.
cordova-plugin-actionsheet 2.3.3 "ActionSheet"
cordova-plugin-photo-library 2.2.1 "Photo Library"
PS C:\Users\Chuck\Documents\IonicApps\conveyor> ionic cordova plugin add cordova-plugin-photo-library --save
> cordova.cmd plugin add cordova-plugin-photo-library
Adding cordova-plugin-photo-library to package.json
PS C:\Users\Chuck\Documents\IonicApps\conveyor> ionic cordova plugin remove cordova-plugin-photo-library
> cordova.cmd plugin remove cordova-plugin-photo-library
Removing "cordova-plugin-photo-library"
Removing cordova-plugin-photo-library from package.json
PS C:\Users\Chuck\Documents\IonicApps\conveyor> ionic cordova plugin add cordova-plugin-photo-library --save
> cordova.cmd plugin add cordova-plugin-photo-library
Adding cordova-plugin-photo-library to package.json
PS C:\Users\Chuck\Documents\IonicApps\conveyor> cordova plugin list
cordova-plugin-actionsheet 2.3.3 "ActionSheet"
cordova-plugin-photo-library 2.2.1 "Photo Library"
Error: ENOENT: no such file or directory, open 'C:\Users\Chuck\.config\configstore\cordova-config.json'
PS C:\Users\Chuck\Documents\IonicApps\conveyor> cordova plugin list
cordova-plugin-actionsheet 2.3.3 "ActionSheet"
cordova-plugin-photo-library 2.2.1 "Photo Library"
Error: ENOENT: no such file or directory, open 'C:\Users\Chuck\.config\configstore\cordova-config.json'
PS C:\Users\Chuck\Documents\IonicApps\conveyor> ionic --version
5.4.1
PS C:\Users\Chuck\Documents\IonicApps\conveyor> cordova --version
9.0.0 (cordova-lib@9.0.1)
PS C:\Users\Chuck\Documents\IonicApps\conveyor>

and everytime I run this app on my test devices (physical devices NOT emulators) I can't seem to get them the library to work. ActionSheet and Camera plugins are working JUST FINE, but the PhotoLibrary seems bugged? Any idea which version I should try/switch to to ensure stability?

i'm running using ionic serve --devapp and running Ionic Devapp on my test devices.

chukwumaokere commented 4 years ago

I have a workaround using the cordova-plugin-camera, since I already use the camera plugin to take photos in my app, I found that I could use some tweaks to the camera options to open the library and select a photo as well. I dont know how well known this method is but it is supported in the documentation, just maybe not well known.

libraryOptions: CameraOptions = {
    quality: 100,
    destinationType: this.camera.DestinationType.FILE_URI,
    encodingType: this.camera.EncodingType.JPEG,
    mediaType: this.camera.MediaType.PICTURE,
    sourceType: this.camera.PictureSourceType.PHOTOLIBRARY
  }

then use this as your function to launch the Photo Library

this.camera.getPicture(this.libraryOptions).then((imageData) => {
          // imageData is either a base64 encoded string or a file URI
          // If it's base64 (DATA_URL):
          let base64Image = 'data:image/jpeg;base64,' + imageData;
          console.log(base64Image);
          // TODO: need code to upload to server here.
        }, (err) => {
          // Handle error
          console.error(err);
        }); 

This will do for my use case. It doesnt support picking multiple photos at once though but what you can do is code an intermediate modal that allows users to pick photos from their library and see the photos they've chosen before submitting the photos.