cordova-plugin-photo-library
cordova-plugin-photo-library copied to clipboard
Success is not a function
Getting error With Ionic 4.
Uncaught TypeError: success is not a function at /plugins/cordova-plugin-photo-library/www/PhotoLibrary.js:44 at handlePhotoURL (/plugins/cordova-plugin-photo-library/www/PhotoLibrary.js:347) at Object.photoLibrary.getPhotoURL (/plugins/cordova-plugin-photo-library/www/PhotoLibrary.js:156) at handleThumbnailURL (/plugins/cordova-plugin-photo-library/www/PhotoLibrary.js:353) at Object.photoLibrary.getThumbnailURL (/plugins/cordova-plugin-photo-library/www/PhotoLibrary.js:126) at addUrlsToLibrary (/plugins/cordova-plugin-photo-library/www/PhotoLibrary.js:361) at processLibrary (/plugins/cordova-plugin-photo-library/www/PhotoLibrary.js:325) at /plugins/cordova-plugin-photo-library/www/PhotoLibrary.js:42 at /plugins/cordova-plugin-photo-library/www/async/dist/async.min.js:2 at process (/plugins/cordova-plugin-photo-library/www/async/dist/async.min.js:2)
Ionic 4 Info
` Ionic:
ionic (Ionic CLI) : 4.10.1 (C:\Users\Munene\AppData\Roaming\npm\node_modules\ionic) Ionic Framework : @ionic/angular 4.0.0 @angular-devkit/build-angular : 0.12.3 @angular-devkit/schematics : 7.2.3 @angular/cli : 7.2.3 @ionic/angular-toolkit : 1.2.2
Cordova:
cordova (Cordova CLI) : 8.1.2 ([email protected]) Cordova Platforms : android 7.1.4 Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.1, (and 7 other plugins)
System:
NodeJS : v10.15.0 (C:\Program Files\nodejs\node.exe) npm : 6.7.0 OS : Windows 10 `
i was having the same problems as you did, and here are my findout:
the problem lies with the Ionic-Native rather than the plugin.
it seems that Ionic-Native had somehow mis-assigned the input parameters to the plugin interface
photoLibrary.getLibrary = function (success, error, options) {...
when you are calling Ionic-Native with an 'option' provided
this.photoLib.getLibrary(option)
the 'option' was somehow assigned to 'success' rather than 'options' of the previous plugin interface ; which had cause the error
for a work-around, just call the Ionic-Native without an 'option'
this.photoLib.getLibrary()
@jing-zhou I'll give it a try. Thanks
We cannot use chunked subscription without using options :/
Same problem any fix for this?
Removing 'options' parameter is not a workaround, because we loss possibility to set important chunk parameters like itemsInChunk or chunkTimeSec. Some fix is needed here
Dropping the ionic interface and using the cordova code right away seems like a good workaround.
cordova.plugins['photoLibrary'].getLibrary(
result => {
const library = result.library;
console.log(library);
},
err => {
console.log('Error occured');
},
{
// optional options
itemsInChunk: 2,
}
);
I do not fully understand the problem you are having. can you be more revealing ?
I leave the piece of code I use to you I tested ionic 3, 4. Working
import { PhotoLibrary, LibraryItem } from '@ionic-native/photo-library';
import { Platform} from 'ionic-angular';
public library: any;
public result : any;
this.platform.ready().then(() => {
this.library = [];
this.photoLibrary.requestAuthorization().then(() => {
this.photoLibrary.getLibrary().subscribe({
next: (chunk) => {
this.library = this.library.concat(chunk);
// To take top 100 images
//this.library = this.library.slice(0, 100);
this.result = this.library;
},
error: err => { if(err.startsWith('Permission')){} },
complete: () => { }
});
})
.catch(err => console.log('permissions weren\'t granted'));
}).catch(err => console.log('no platform') );