As a result of Apple rejecting my app I've had to turn it into a PWA and I'm having issues implementing some functionality. I'm unable to access images now...I was initially using image picker but that obviously won't work now.
Here is the error I'm getting on Safari:
Service Worker context closed
Here's how I'm currently getting images:
encodeImageUri(imageUri: any, callback: any): void {
const c = document.createElement('canvas');
const ctx = c.getContext('2d');
const img = new Image();
img.onload = function() {
const aux: any = this;
c.width = aux.width;
c.height = aux.height;
ctx.drawImage(img, 0, 0);
const dataURL = c.toDataURL('image/jpeg');
callback(dataURL);
};
img.src = imageUri;
}
async uploadImage(image: any, photoName: any, userId: any): Promise<any> {
const imageRef = this.storageRef.child(`${userId}`).child(`${photoName}`);
const imageURI = this.webview.convertFileSrc(image);
return new Promise<any>(async (resolve, reject) => {
this.encodeImageUri(imageURI, (image64: string) => {
imageRef.putString(image64, 'data_url')
.then(snapshot => {
snapshot.ref.getDownloadURL()
.then(res => resolve(res));
}, err => {
reject(err);
});
});
});
}
I've searched online and on Stack but I can't find an example of how to upload images on a PWA.
The closest thing to a resolution is a few articles on registering the service worker but it doesn't really explain where this needs to be done.
This is the example but I'm not clear on where this needs to be done or if it should to resolve this issue https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register