Closed nitricware closed 1 year ago
Can you provide a project (for example a zip archive) to reproduce this issue? I tried in my app and it is not happening...
Yes, it happens in this project: https://github.com/nitricware/pSTaRT
I was experiencing this issue as well. This seems to be related to these stack overflow questions:
However, this only happened when I tried to access my own AVCaptureDevice
and enabling the torch myself. @nitricware question made me discover the isTorchOn
parameter for CodeScannerView
, and after I tried using it I saw the torch working as expected.
I don't know much more about this bug, I'm sorry 😕
Maybe related to #70
I think the problem boils down to these LOCs here
let fallbackVideoCaptureDevice = AVCaptureDevice.default(for: .video)
and here
if let backCamera = AVCaptureDevice.default(for: AVMediaType.video),
So the quickfix is to use the exact same AVCaptureDevice
on both lines, the proper fix would be to pass explicitly set AVCaptureDevice
to the updateViewController
-function, I think.
I changed my code, so that the CodeScannerView
gets passed a @State
and the torch is off initially. I also implemented a button as suggested in #70 but when I press the button the torch switches on as expected, however the camera freezes.
When I touch the button again, the torch switches off and the camera comes back to life.
Edit: I think i fixed it with #111
Tested on an iPhone 11 Pro running iOS 16;
With
isTorchOn
set totrue
the torch can show three behaviours - none of which is reliable:The View is presented in a Sheet: