From 4ab43db1ee602252b4a03fd6f060c06ac42bd89e Mon Sep 17 00:00:00 2001 From: Philippe Geoffroy Date: Mon, 30 Oct 2023 20:41:55 +0100 Subject: [PATCH] Fix: with the "noDuplicates" detection speed, the same code is no longer detected after stopping and restarting the scanner. Fix: spamming code detection with "noDuplicates" detection speed on iOS. --- .../dev/steenbakker/mobile_scanner/MobileScanner.kt | 3 ++- ios/Classes/MobileScanner.swift | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt b/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt index 518c993ee..6e3495915 100644 --- a/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt +++ b/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt @@ -70,7 +70,7 @@ class MobileScanner( scanner.process(inputImage) .addOnSuccessListener { barcodes -> if (detectionSpeed == DetectionSpeed.NO_DUPLICATES) { - val newScannedBarcodes = barcodes.map { barcode -> barcode.rawValue } + val newScannedBarcodes = barcodes.mapNotNull({ barcode -> barcode.rawValue }).sorted() if (newScannedBarcodes == lastScanned) { // New scanned is duplicate, returning return@addOnSuccessListener @@ -224,6 +224,7 @@ class MobileScanner( throw AlreadyStarted() } + lastScanned = null scanner = if (barcodeScannerOptions != null) { BarcodeScanning.getClient(barcodeScannerOptions) } else { diff --git a/ios/Classes/MobileScanner.swift b/ios/Classes/MobileScanner.swift index 8b0cca35a..51a63d66c 100644 --- a/ios/Classes/MobileScanner.swift +++ b/ios/Classes/MobileScanner.swift @@ -117,12 +117,13 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega imagesCurrentlyBeingProcessed = false if (detectionSpeed == DetectionSpeed.noDuplicates) { - let newScannedBarcodes = barcodes?.map { barcode in + let newScannedBarcodes = barcodes?.compactMap({ barcode in return barcode.rawValue - } + }).sorted() + if (error == nil && barcodesString != nil && newScannedBarcodes != nil && barcodesString!.elementsEqual(newScannedBarcodes!)) { return - } else { + } else if (newScannedBarcodes?.isEmpty == false) { barcodesString = newScannedBarcodes } } @@ -139,6 +140,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega throw MobileScannerError.alreadyStarted } + barcodesString = nil scanner = barcodeScannerOptions != nil ? BarcodeScanner.barcodeScanner(options: barcodeScannerOptions!) : BarcodeScanner.barcodeScanner() captureSession = AVCaptureSession() textureId = registry?.register(self)