cordova - Windows 10 Mobile - App crashes when selecting from the gallery -


so have used cordova-plugin-camera in project make photos , select gallery.

my android- , ios app not have problems @ all. when testing out on live windows 10 mobile device, app crashes after selected image gallery.

the camera work though.

the code use (simplified)

this.camera.getpicture({   quality: 50,   destinationtype: this.camera.destinationtype.file_uri,   sourcetype: this.camera.picturesourcetype.photolibrary,   encodingtype: this.camera.encodingtype.jpeg,   mediatype: this.camera.mediatype.picture,   savetophotoalbum: false,           //gave problems in windows   correctorientation: true }).then(imageuri => {   this.navctrl.push(page2, {image: imageuri}); }, err => {   // ionic alert, way of still showing alerts windows users   this.alertctrl.create({message: err}).present(); }); 

and in page2 component have, before gets executed, alert show imageuri passed.

neither success nor error callback executed, app shuts down.

i tried adding try-catch around seems doesn't throw error. (at least, catch doesn't catch it.)

so in windows universal application, can't access photo-library when building cordova application (at least, haven't yet found how). because of read-/write-access on files. (imagine opening windows 10 app on desktop , having photo's lined you, wouldn't great idea).

a workaround use file-input , triggering on button click (so ui doesn't change). way user gets pick file him/her/itself , provides app read-/write access file.

the html bit this:

<input type="file" hidden #file (change)="filechanged()"></input> <button (click)="file.click()">my custom button</button> 

and read src (as datauri) fileinput:

filechange(event) {     // show loading screen, not fast on uwp     let loading = this.loadingctrl.create({       content: 'processing photo...'     });     loading.present();      let filelist: filelist = event.target.files;     if(filelist.length > 0) {       let file: file = filelist[0];       var reader = new filereader();        // define callback seperate onload, else e.target.result undefined       let callback = (e) => {           loading.dismiss();           let src = e.target.result;       };        reader.onload = callback;        reader.readasdataurl(event.target.files[0]);     }   } 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -