Recently, I've been working on updating an old app that was using an outdated version of the camera-preview plugin. The previous version had a method called setOnPictureTakenHandler
which allowed me to easily retrieve the image URL.
However, the new version of the plugin has replaced that method with takePicture()
which requires defining an onSuccess function to return the URL of the image. The tricky part is that I'm unable to access this URL outside of the onSuccess function.
As I am transitioning to TypeScript, I suspect that I might be mishandling variables. I've implemented a provider for the cameraPreview and created an envelope for the takePicture()
method of the plugin. The goal is to have this envelope return the URL to the controller where the provider is injected.
Below is the code for the provider's envelope:
url:string;
takePictures2() :string {
this.cameraPreview.takePicture(function(imgData){
this.url = "data:image/jpeg;base64" + imgData;
}).then();
return this.url;
};
And here is the code for the controller:
takePictures() {
let url : string = this.cameraPreview.takePictures2();
console.log(url);
}