Skip to content

Commit

Permalink
Fix: with the "noDuplicates" detection speed, the same code is no lon…
Browse files Browse the repository at this point in the history
…ger detected after stopping and restarting the scanner.

Fix: spamming code detection with "noDuplicates" detection speed on iOS.
  • Loading branch information
Philippe Geoffroy committed Oct 30, 2023
1 parent 30b037c commit 4ab43db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -224,6 +224,7 @@ class MobileScanner(
throw AlreadyStarted()
}

lastScanned = null
scanner = if (barcodeScannerOptions != null) {
BarcodeScanning.getClient(barcodeScannerOptions)
} else {
Expand Down
8 changes: 5 additions & 3 deletions ios/Classes/MobileScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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)
Expand Down

0 comments on commit 4ab43db

Please sign in to comment.