0

I am building an Ionic app that uses the camera plugin, and I am having problems with getting the data to come back from the camera. As the Capacitor docs on the Camera plugin (In the paragraph above the variables section) say, the app will sometimes be "terminated" in the background and so when it returns to the app, you need to listen for the "appRestoredResult in the App plugin" to get the camera result. The problem that I am having is that this event never seems to fire.

I added listeners for the following events: backButton, pause, resume, appRestoredResult, and appStateChange.

  • backButton works, and shows the toast notification (which is what I was using to test to see if the events were fired).
  • pause seems to only be fired if I press the "home" or "opened apps" button (the ones on the phone, not part of my app).
  • resume only fires when I return to the app after the pause event successfully fired. This event should also fire when I come back from the camera as well, shouldn't it?
  • appRestoredResult doesn't seem to fire ever. Which it should fire after returning to the app after the camera (if the app was terminated during the picture taking).
  • appStateChange fires when I pause or resume the app.

What am I doing wrong?

1 Answer 1

0

With a little more digging and a little more testing, I figured out the problem.

The reason why appRestoredResult event isn't firing, is because it only works with a specific camera library (which I had switched to previous to see if I could get that to work, but then I started using these events, and didn't switch back).

This is what I had previously

...
import { App } from "@capacitor/app";
import { Camera } from "@ionic-native/camera/ngx";
...

This is what I have now

...
import { App } from "@capacitor/app";
import { Camera } from "@capacitor/camera";
...

So if you are having trouble with the appRestoredResult event not firing, check your libraries and make sure you are using both from @capacitor.

Sign up to request clarification or add additional context in comments.

3 Comments

hi, i already using @capacitor/camera and @capacitor/app, but appRestoredResult still not fire. do you know how to fix that? thank you.
I can't say right now. I would need more info and to see your code
hi. i am sorry for the late reply. this is my code, i using framework angular and ionic. before take picture, i log "start...", but log result not fire. and appRestoredResult not fire too. constructor() { App.addListener('appRestoredResult', (data) => { console.log(‘appRestoredResult: ’, data); }); } takePicture() { console.log(‘start….’); const image = await Camera.getPhoto({ quality: 90, allowEditing: false, resultType: CameraResultType.Uri, saveToGallery: false, source: CameraSource.Camera }); console.log(‘result…’, image); };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.