@@ -22,6 +22,8 @@ extension CodeScannerView {
22
22
var lastTime = Date ( timeIntervalSince1970: 0 )
23
23
private let showViewfinder : Bool
24
24
25
+ let fallbackVideoCaptureDevice = AVCaptureDevice . default ( for: . video)
26
+
25
27
private var isGalleryShowing : Bool = false {
26
28
didSet {
27
29
// Update binding
@@ -145,7 +147,6 @@ extension CodeScannerView {
145
147
146
148
var captureSession : AVCaptureSession ?
147
149
var previewLayer : AVCaptureVideoPreviewLayer !
148
- let fallbackVideoCaptureDevice = AVCaptureDevice . default ( for: . video)
149
150
150
151
private lazy var viewFinder : UIImageView ? = {
151
152
guard let image = UIImage ( named: " viewfinder " , in: . module, with: nil ) else {
@@ -416,12 +417,14 @@ extension CodeScannerView {
416
417
#endif
417
418
418
419
func updateViewController( isTorchOn: Bool , isGalleryPresented: Bool , isManualCapture: Bool , isManualSelect: Bool ) {
419
- if let backCamera = AVCaptureDevice . default ( for: AVMediaType . video) ,
420
- backCamera. hasTorch
421
- {
422
- try ? backCamera. lockForConfiguration ( )
423
- backCamera. torchMode = isTorchOn ? . on : . off
424
- backCamera. unlockForConfiguration ( )
420
+ guard let videoCaptureDevice = parentView. videoCaptureDevice ?? fallbackVideoCaptureDevice else {
421
+ return
422
+ }
423
+
424
+ if videoCaptureDevice. hasTorch {
425
+ try ? videoCaptureDevice. lockForConfiguration ( )
426
+ videoCaptureDevice. torchMode = isTorchOn ? . on : . off
427
+ videoCaptureDevice. unlockForConfiguration ( )
425
428
}
426
429
427
430
if isGalleryPresented && !isGalleryShowing {
0 commit comments