capawesome-team / capacitor-mlkit

⚡️ ML Kit plugins for Capacitor. Supports Android and iOS.
https://capawesome.io/plugins/mlkit/
Apache License 2.0
147 stars 46 forks source link

fix(barcode-scanning): add delay before starting camera session #188

Closed robingenz closed 1 month ago

robingenz commented 1 month ago

Pull request checklist

Please check if your PR fulfills the following requirements:


Close #176

pkg-pr-new[bot] commented 1 month ago

Open in Stackblitz

@capacitor-mlkit/barcode-scanning

``` npm i https://pkg.pr.new/capawesome-team/capacitor-mlkit/@capacitor-mlkit/barcode-scanning@188 ```

@capacitor-mlkit/face-detection

``` npm i https://pkg.pr.new/capawesome-team/capacitor-mlkit/@capacitor-mlkit/face-detection@188 ```

@capacitor-mlkit/face-mesh-detection

``` npm i https://pkg.pr.new/capawesome-team/capacitor-mlkit/@capacitor-mlkit/face-mesh-detection@188 ```

@capacitor-mlkit/selfie-segmentation

``` npm i https://pkg.pr.new/capawesome-team/capacitor-mlkit/@capacitor-mlkit/selfie-segmentation@188 ```

@capacitor-mlkit/translation

``` npm i https://pkg.pr.new/capawesome-team/capacitor-mlkit/@capacitor-mlkit/translation@188 ```

commit: 8f2eb9b

TimvdEijnden commented 1 month ago

When will this be released?

robingenz commented 1 month ago

@TimvdEijnden I was still waiting to see if there would be more feedback.

TimvdEijnden commented 1 month ago

I can try the pkg.new version, because I got an issue only on iOS that the camera is not showing up

jimcase commented 1 month ago

Thanks @robingenz for tackling the camera issue.

While the 0.1s delay might help in some cases, it feels more like a temporary workaround than a solid fix. The main issue is that commitConfiguration() sometimes runs asynchronously, causing startRunning() to be called prematurely. Ideally, the solution should ensure commitConfiguration() fully completes before proceeding, without relying on a fixed delay.

We've tested this approach in another project (PR: https://github.com/cardano-foundation/cf-identity-wallet/pull/772) and found that the delay didn't consistently resolve the issue. A more reliable method would be preferable.

Error:

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration'
*** First throw call stack:
(0x18441908c 0x18171b2e4 0x1a25838f0 0x104a86d84 0x1063d8d68 0x1063d8de8 0x105a84a30 0x105a8671c 0x105a9ae58 0x105a9b618 0x20b78bc40 0x20b788488)
libc++abi: terminating due to uncaught exception of type NSException
robingenz commented 1 month ago

@jimcase Yes, I know that's not an ideal solution. Unfortunately, I can't think of any other solution at the moment. If you have an idea, you are welcome to create a PR and I'll take a look at it.