Plugin(s)
Version
8.1.0
Platform(s)
Current behavior
On iOS switching lensFacing between FRONT and BACK sometimes gives a black screen (and the camera doesn't start).
Expected behavior
Switch between FRONT and BACK camera without issues.
Reproduction
https://github.com/lajuffermans/capacitor-mlkit-plugin-demo
Steps to reproduce
- Clone the repo
- Build and run it
- In the demo app go to "Barcode Scanning"
- Select "Start scan" (make sure you requested camera permissions)
- In the bottom left corner there is a button to toggle between front and back camera, use it a couple of times and you get a black screen.
Other information
- Only noticed this on iOS
- At first I tried to solve this by manually use
stopScan and then startScan with the new lensFacing valu however when I looked at the code I noticed startScan already calls stopScan
- I'm not an iOS expert so I asked Claude (yes here we go) and Claude suggested to add a
self.cameraView?.stopCaptureSession() in the stopScan of BarcodeScanner and it added this to BarcodeScannerView:
// Breaks the AVCaptureVideoDataOutput→delegate retain cycle and stops the session.
// Must be called explicitly before releasing the view; deinit cannot be relied upon
// because setSampleBufferDelegate holds a strong reference, preventing deallocation.
public func stopCaptureSession() {
captureSession?.outputs.forEach {
($0 as? AVCaptureVideoDataOutput)?.setSampleBufferDelegate(nil, queue: nil)
}
captureSession?.stopRunning()
}
I have to say, that does work for me but I'd rather have an expert look at it ;)
Capacitor doctor
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 8.3.4
@capacitor/core: 8.3.4
@capacitor/android: 8.3.4
@capacitor/ios: 8.3.4
Installed Dependencies:
@capacitor/cli: 8.3.4
@capacitor/core: 8.3.4
@capacitor/android: 8.3.4
@capacitor/ios: 8.3.4
[success] iOS looking great! 👌
[success] Android looking great! 👌
Before submitting
Plugin(s)
Version
8.1.0
Platform(s)
Current behavior
On iOS switching lensFacing between FRONT and BACK sometimes gives a black screen (and the camera doesn't start).
Expected behavior
Switch between FRONT and BACK camera without issues.
Reproduction
https://github.com/lajuffermans/capacitor-mlkit-plugin-demo
Steps to reproduce
Other information
stopScanand thenstartScanwith the new lensFacing valu however when I looked at the code I noticedstartScanalready callsstopScanself.cameraView?.stopCaptureSession()in thestopScanofBarcodeScannerand it added this toBarcodeScannerView:I have to say, that does work for me but I'd rather have an expert look at it ;)
Capacitor doctor
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 8.3.4
@capacitor/core: 8.3.4
@capacitor/android: 8.3.4
@capacitor/ios: 8.3.4
Installed Dependencies:
@capacitor/cli: 8.3.4
@capacitor/core: 8.3.4
@capacitor/android: 8.3.4
@capacitor/ios: 8.3.4
[success] iOS looking great! 👌
[success] Android looking great! 👌
Before submitting