@@ -12,7 +12,7 @@ import UIKit
12
12
@available ( macCatalyst 14 . 0 , * )
13
13
extension CodeScannerView {
14
14
15
- public class ScannerViewController : UIViewController , UIImagePickerControllerDelegate , UINavigationControllerDelegate , AVCaptureMetadataOutputObjectsDelegate , UIAdaptivePresentationControllerDelegate {
15
+ public class ScannerViewController : UIViewController , UIImagePickerControllerDelegate , UINavigationControllerDelegate , UIAdaptivePresentationControllerDelegate {
16
16
private let photoOutput = AVCapturePhotoOutput ( )
17
17
private var isCapturing = false
18
18
private var handler : ( ( UIImage ) -> Void ) ?
@@ -449,48 +449,6 @@ extension CodeScannerView {
449
449
lastTime = Date ( )
450
450
}
451
451
452
- public func metadataOutput( _ output: AVCaptureMetadataOutput , didOutput metadataObjects: [ AVMetadataObject ] , from connection: AVCaptureConnection ) {
453
- if let metadataObject = metadataObjects. first {
454
- guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else { return }
455
- guard let stringValue = readableObject. stringValue else { return }
456
-
457
- guard didFinishScanning == false else { return }
458
-
459
- let photoSettings = AVCapturePhotoSettings ( )
460
- guard !isCapturing else { return }
461
- isCapturing = true
462
-
463
- handler = { [ self ] image in
464
- let result = ScanResult ( string: stringValue, type: readableObject. type, image: image, corners: readableObject. corners)
465
-
466
- switch parentView. scanMode {
467
- case . once:
468
- found ( result)
469
- // make sure we only trigger scan once per use
470
- didFinishScanning = true
471
-
472
- case . manual:
473
- if !didFinishScanning, isWithinManualCaptureInterval ( ) {
474
- found ( result)
475
- didFinishScanning = true
476
- }
477
-
478
- case . oncePerCode:
479
- if !codesFound. contains ( stringValue) {
480
- codesFound. insert ( stringValue)
481
- found ( result)
482
- }
483
-
484
- case . continuous:
485
- if isPastScanInterval ( ) {
486
- found ( result)
487
- }
488
- }
489
- }
490
- photoOutput. capturePhoto ( with: photoSettings, delegate: self )
491
- }
492
- }
493
-
494
452
func isPastScanInterval( ) -> Bool {
495
453
Date ( ) . timeIntervalSince ( lastTime) >= parentView. scanInterval
496
454
}
@@ -516,6 +474,52 @@ extension CodeScannerView {
516
474
}
517
475
}
518
476
477
+ // MARK: - AVCaptureMetadataOutputObjectsDelegate
478
+
479
+ extension CodeScannerView . ScannerViewController : AVCaptureMetadataOutputObjectsDelegate {
480
+ public func metadataOutput( _ output: AVCaptureMetadataOutput , didOutput metadataObjects: [ AVMetadataObject ] , from connection: AVCaptureConnection ) {
481
+ if let metadataObject = metadataObjects. first {
482
+ guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else { return }
483
+ guard let stringValue = readableObject. stringValue else { return }
484
+
485
+ guard didFinishScanning == false else { return }
486
+
487
+ let photoSettings = AVCapturePhotoSettings ( )
488
+ guard !isCapturing else { return }
489
+ isCapturing = true
490
+
491
+ handler = { [ self ] image in
492
+ let result = ScanResult ( string: stringValue, type: readableObject. type, image: image, corners: readableObject. corners)
493
+
494
+ switch parentView. scanMode {
495
+ case . once:
496
+ found ( result)
497
+ // make sure we only trigger scan once per use
498
+ didFinishScanning = true
499
+
500
+ case . manual:
501
+ if !didFinishScanning, isWithinManualCaptureInterval ( ) {
502
+ found ( result)
503
+ didFinishScanning = true
504
+ }
505
+
506
+ case . oncePerCode:
507
+ if !codesFound. contains ( stringValue) {
508
+ codesFound. insert ( stringValue)
509
+ found ( result)
510
+ }
511
+
512
+ case . continuous:
513
+ if isPastScanInterval ( ) {
514
+ found ( result)
515
+ }
516
+ }
517
+ }
518
+ photoOutput. capturePhoto ( with: photoSettings, delegate: self )
519
+ }
520
+ }
521
+ }
522
+
519
523
@available ( macCatalyst 14 . 0 , * )
520
524
extension CodeScannerView . ScannerViewController : AVCapturePhotoCaptureDelegate {
521
525
0 commit comments