From d0d5f06e356113e51e44deaeaf3d8720ef2414a9 Mon Sep 17 00:00:00 2001 From: Robin Genz Date: Wed, 25 Sep 2024 06:46:20 +0200 Subject: [PATCH 1/2] fix(barcode-scanning): add delay before starting camera session --- .../barcode-scanning/ios/Plugin/BarcodeScannerView.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/barcode-scanning/ios/Plugin/BarcodeScannerView.swift b/packages/barcode-scanning/ios/Plugin/BarcodeScannerView.swift index b24cef9..919ede0 100644 --- a/packages/barcode-scanning/ios/Plugin/BarcodeScannerView.swift +++ b/packages/barcode-scanning/ios/Plugin/BarcodeScannerView.swift @@ -61,7 +61,13 @@ public protocol BarcodeScannerViewDelegate { throw RuntimeError(implementation.plugin.errorCannotAddCaptureOutput) } captureSession.commitConfiguration() - + // `session.startRunning()` should be called after `session.commitConfiguration()` is complete. + // However, occacsionally `commitConfiguration()` runs asynchronously, so when `startRunning()` + // is called, `commitConfiguration()` is still in progress and the state is still `uncommited`. + // This can be reproduced by repeatedly switching or toggling the camera using the plugin demo. + // Adding a 100ms delay ensures that `session.commitConfiguration()` is complete before calling + // `session.startRunning()`. + Thread.sleep(forTimeInterval: 0.1) DispatchQueue.global(qos: .background).async { captureSession.startRunning() } From 8f2eb9b04149530f8bba2f9a5ecaded05eea61b4 Mon Sep 17 00:00:00 2001 From: Robin Genz Date: Mon, 7 Oct 2024 10:07:49 +0200 Subject: [PATCH 2/2] docs --- .changeset/hungry-trees-raise.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hungry-trees-raise.md diff --git a/.changeset/hungry-trees-raise.md b/.changeset/hungry-trees-raise.md new file mode 100644 index 0000000..9860667 --- /dev/null +++ b/.changeset/hungry-trees-raise.md @@ -0,0 +1,5 @@ +--- +'@capacitor-mlkit/barcode-scanning': patch +--- + +fix(ios): add delay before starting camera session