Closed mixuala closed 3 years ago
The actual cordova plugin seems to be working correctly. It's just access through IonicNative that fails.
cordovaScan(){
// this.platform.ready()
const photolib = cordova.plugins['photoLibrary'];
photolib.getLibrary(
(chunk)=>{
chunk.library.forEach( (libraryItem)=> {
console.log(libraryItem.id, libraryItem);
})
if (chunk.isLastChunk)
console.log("DONE")
},
(err)=>console.log(err),
options
)
}
IonicNative: PhotoLibrary.getLibrary()
has the wrong interface.
IonicNative:
PhotoLibrary.getLibrary : (options?: GetLibraryOptions)=>Observable<LibraryItem[]>
Cordova Plugin:
PhotoLibrary.getLibrary : (success, error, options)=>void
I wrote this method to bridge the gap:
/**
* IonicNative.PhotoLibrary.getLibrary does not match CordovaPlugin.PhotoLibrary.getLibrary
* IonicNative: PhotoLibrary.getLibrary = (options?: GetLibraryOptions)=>Observable<LibraryItem[]>;
* but `cordova-plugin-photo-library` expects:
* Cordova: PhotoLibrary.getLibrary = (success, error, options)=>void
*/
function patch_IonicNativePhotoLibrary(photoLibrary:IonicNativePhotoLibrary):void {
// force typescript type check to match cordova getLibrary()
let native_getLibrary:(success:any, error:any, options:GetLibraryOptions)=>void = photoLibrary.getLibrary;
let done:Subscription;
if (!photoLibrary['getLibrary_0']) {
native_getLibrary = photoLibrary.getLibrary;
photoLibrary['getLibrary_0'] = native_getLibrary;
}
const resp$ = new Subject<LibraryItem[]>();
const callbacks = {
success: (resp:{isLastChunk:boolean, library:LibraryItem[]})=>{
resp$.next(resp.library);
if (resp.isLastChunk) {
resp$.complete();
done.unsubscribe();
}
},
error: (err)=>{
resp$.error(err);
resp$.complete();
done.unsubscribe();
}
};
photoLibrary['getLibrary_patched'] = (options:GetLibraryOptions): Observable<LibraryItem[]> => {
done = photoLibrary['getLibrary_0'](callbacks.success, callbacks.error, options).subscribe();
return resp$.asObservable();
}
photoLibrary.getLibrary = photoLibrary['getLibrary_patched'];
}
There has been no recent activity and this issue has been marked inactive.
I'm submitting a ... (check one with "x") [ x ] bug report [ ] feature request [ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://ionicworldwide.herokuapp.com/
Current behavior:
const photolib = self.photoLibrary.getLibrary()
returnsundefined
when using IonicNative, but the cordova plugin works fine.tested with "@ionic-native/photo-library": "^5.0.0-beta.21",
Expected behavior: should get an observable
Steps to reproduce:
add method to
home.page.ts
Related code:
Other information:
Ionic info: (run
ionic info
from a terminal/cmd prompt and paste output below):