Skip to content

Commit

Permalink
fix(barcode-scanning): add delay before starting camera session (#188)
Browse files Browse the repository at this point in the history
* fix(barcode-scanning): add delay before starting camera session

* docs
  • Loading branch information
robingenz authored Oct 7, 2024
1 parent 34bfb08 commit a0198b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/hungry-trees-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@capacitor-mlkit/barcode-scanning': patch
---

fix(ios): add delay before starting camera session
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit a0198b6

Please sign in to comment.