Navaron Bracke

use a lazy initialized scanner for iOS

@@ -22,8 +22,8 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega @@ -22,8 +22,8 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
22 /// The selected camera 22 /// The selected camera
23 var device: AVCaptureDevice! 23 var device: AVCaptureDevice!
24 24
25 - /// Barcode scanner for results  
26 - var scanner = BarcodeScanner.barcodeScanner() 25 + /// The long lived barcode scanner for scanning barcodes from a camera preview.
  26 + var scanner: BarcodeScanner? = nil
27 27
28 /// Default position of camera 28 /// Default position of camera
29 var videoPosition: AVCaptureDevice.Position = AVCaptureDevice.Position.back 29 var videoPosition: AVCaptureDevice.Position = AVCaptureDevice.Position.back
@@ -146,7 +146,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega @@ -146,7 +146,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
146 position: videoPosition 146 position: videoPosition
147 ) 147 )
148 148
149 - scanner.process(image) { [self] barcodes, error in 149 + scanner?.process(image) { [self] barcodes, error in
150 imagesCurrentlyBeingProcessed = false 150 imagesCurrentlyBeingProcessed = false
151 151
152 if (detectionSpeed == DetectionSpeed.noDuplicates) { 152 if (detectionSpeed == DetectionSpeed.noDuplicates) {
@@ -314,6 +314,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega @@ -314,6 +314,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
314 textureId = nil 314 textureId = nil
315 captureSession = nil 315 captureSession = nil
316 device = nil 316 device = nil
  317 + scanner = nil
317 } 318 }
318 319
319 /// Toggle the torch. 320 /// Toggle the torch.