Hey!
I want to implement a simple camera feature. The user should be able to take a photo, which is then passed on to firebase storage. Uploading shouldn’t be a big problem, although when pressing “Use Photo” after taking it, the app throws an error: “[error] ERROR {}” in the Xcode console log. I am trying to figure out what the issue could be but can’t seem to find it.
Here is my simplified code for taking and uploading the image:
// Take photo
pickOrTakePhoto() {
console.log("About to take photo");
return new Promise(async (resolve, reject) => {
try {
const image = await Camera.getPhoto({
quality: 90,
resultType: CameraResultType.DataUrl,
source: CameraSource.Prompt,
});
console.log("Got through. "); // <-- This doesn't fire so the problem should be the getPhoto() function.
const storageRef = this.storage.ref('/files/' + new Date().getTime().toString());
const uploadTask = await storageRef.put(image.dataUrl, {contentType: 'image/' + image.format});
resolve(uploadTask);
}
catch (error) {
console.error("Error when processing photo: " + error);
reject(error);
}
});
}
Here is a copy of the error I get in the Xcode console log:
[error] - Unable to load PWA Element 'pwa-camera-modal'. See the docs: https://capacitorjs.com/docs/pwa-elements.
2021-07-08 17:57:33.665785+0200 App[12210:3921790] [Camera] Failed to read exposureBiasesByMode dictionary: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is NULL" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is NULL}
⚡️ [error] - ERROR {}
OBS! The error about not being able to load the PWA element shouldn’t play a role, because I run the app in the native app on my iPhone X.
One thing to note is that CameraResultType.Uri seems to get through, meaning the console.log after taking the photo gets logged. The only options not working are CameraResultType.Base64 and CameraResultType.DataUrl, which I need to upload to firebase.
Ionic 5 with Capacitor 3
I really appreciate all the help I can get! Thanks!