cordova-plugin-photo-library
cordova-plugin-photo-library copied to clipboard
ERROR: Method 'requestAuthorization:' not defined in Plugin 'PhotoLibrary'
When i run app on iOS Device and fetch photo gallery it will throw below error
ERROR: Method 'requestAuthorization:' not defined in Plugin 'PhotoLibrary'
FAILED pluginJSON = ["PhotoLibrary815393554","PhotoLibrary","requestAuthorization",[{"write":true,"read":true}]]
when i run using ionic DevApp it will say plugin_not_installed
i also added photo library plugin in app.modules.ts file
Here is my ionic info
Ionic:
ionic (Ionic CLI) : 4.10.2 (/Users/atologistimac2/node_modules/ionic)
Ionic Framework : @ionic/angular 4.3.0
@angular-devkit/build-angular : 0.13.8
@angular-devkit/schematics : 7.2.4
@angular/cli : 7.3.8
@ionic/angular-toolkit : 1.4.1
Cordova:
cordova (Cordova CLI) : 8.1.2 ([email protected])
Cordova Platforms : ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.0.1, (and 7 other plugins)
System:
ios-deploy : 1.9.4
NodeJS : v10.15.1 (/usr/local/bin/node)
npm : 6.9.0
OS : macOS High Sierra
Xcode : Xcode 10.1 Build version 10B61
Here is my ionic cordova plugin list
cordova-plugin-add-swift-support 2.0.2 "AddSwiftSupport"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 4.0.1 "cordova-plugin-ionic-webview"
cordova-plugin-photo-library 2.2.1 "Photo Library"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
Here i have a function for get photos
this.platform.ready()
.then(() => {
this.photolibrary.requestAuthorization({read: true, write: true})
.then((value) => {
console.log('Request Success: ', value);
this.showToast('Success');
}, (err) => {
this.showToast(err.toString());
console.log('Request Error: ', err);
}).catch((err) => {
this.showToast('Catch Error');
console.log('Catch error: ', err);
});
});
don't know what i am doing wrong here, can anyone please help me to figure out this issue?
+1
+1
Not working with iOS 12 at all.
+1
Hi guys This is how i resolved it... its better to install the following plugins with correct versions and it will work perfectly.
cordova plugin rm cordova-plugin-add-swift-support cordova plugin rm cordova-plugin-photo-library
cordova plugin add [email protected] cordova plugin add https://github.com/nilebma/cordova-plugin-photo-library.git
and everything will work fine again. If you face any issue just delete these plugins from plugins folder manually and then install the plugins.
@codecrab-studios Thanks man.. it's working fine now..
@codecrab-studios Thanks, Now it is asking for permission, but after that if i want to get Library it will not print anything in console,
i try below code:
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 AlbumItem, only of includeAlbumsData was used
});
},
error: err => { console.log('could not get photos'); },
complete: () => { console.log('done getting photos'); }
});
})
.catch(err => console.log('permissions weren\'t granted'));
are you able to get photos details?
@atologistkaushik Actually i was using this plugin for only downloading images to photo library. I will try this as well to check if thats working or not. Also, once the permission is granted, it works second time you open that page again, maybe...
@codecrab-studios Thanks for your fast replay, i try many time but i get nothing in library, or not even going to error or complete block
@atologistkaushik ok lemme give it a try, will message back you quickly after testing it out!
@atologistkaushik have you try to change the console into alert?
library.forEach(function(libraryItem) { document.getElementById("img_header").src=libraryItem.photoURL; });
this is a sample of my code that i've been using and it's working fine.
@jasonbonfadri Change to alert doesn't affect anything.
try above code also but it also not working for me
if i check library that contain anything using below code
if (library === undefined) {
this.showToast('Library undefined');
} else {
this.showToast('Library not undefined');
}
than it will show
Library undefined
have you any working demo on git ? than please share a link.
FYI, since https://github.com/terikon/cordova-plugin-photo-library/issues/163#issuecomment-485805403 was posted, the forked repo (@nilebma) merged a change that bumped up cordova swift support requirement to 2.0.2, so the suggested solution doesn't compile. To fix this, downgrade it back to 1.7.2 (in plugin.xml). Confirmed that everything works on iOS 12.4 (I have a deployment target of 10.1), no requestAuthorization errors.
FYI, since #163 (comment) was posted, the forked repo (@nilebma) merged a change that bumped up cordova swift support requirement to
2.0.2, so the suggested solution doesn't compile. To fix this, downgrade it back to1.7.2(in plugin.xml). Confirmed that everything works on iOS 12.4 (I have a deployment target of 10.1), no requestAuthorization errors.
Do we need to run any command after making this change?