@@ -15,7 +15,7 @@ extension CodeScannerView {
1515 public class ScannerViewController : UIViewController , UINavigationControllerDelegate {
1616 private let photoOutput = AVCapturePhotoOutput ( )
1717 private var isCapturing = false
18- private var handler : ( ( UIImage ) -> Void ) ?
18+ private var handler : ( ( UIImage ? ) -> Void ) ?
1919 var parentView : CodeScannerView !
2020 var codesFound = Set < String > ( )
2121 var didFinishScanning = false
@@ -438,12 +438,7 @@ extension CodeScannerView.ScannerViewController: AVCaptureMetadataOutputObjectsD
438438 if let metadataObject = metadataObjects. first {
439439 guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else { return }
440440 guard let stringValue = readableObject. stringValue else { return }
441-
442- guard didFinishScanning == false else { return }
443-
444- let photoSettings = AVCapturePhotoSettings ( )
445- guard !isCapturing else { return }
446- isCapturing = true
441+ guard !didFinishScanning && !isCapturing else { return }
447442
448443 handler = { [ self ] image in
449444 let result = ScanResult ( string: stringValue, type: readableObject. type, image: image, corners: readableObject. corners)
@@ -472,7 +467,13 @@ extension CodeScannerView.ScannerViewController: AVCaptureMetadataOutputObjectsD
472467 }
473468 }
474469 }
475- photoOutput. capturePhoto ( with: photoSettings, delegate: self )
470+
471+ if parentView. requirePhotoOutput {
472+ isCapturing = true
473+ photoOutput. capturePhoto ( with: AVCapturePhotoSettings ( ) , delegate: self )
474+ } else {
475+ handler ? ( nil )
476+ }
476477 }
477478 }
478479}
0 commit comments