Julian Steenbakker
Committed by GitHub

Merge pull request #512 from juliansteenbakker/bug/fix-analyze-image

fix: fixed barcodes not found on analyzeImage
@@ -220,16 +220,19 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin { @@ -220,16 +220,19 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
220 details: nil)) 220 details: nil))
221 return 221 return
222 } 222 }
  223 +
223 mobileScanner.analyzeImage(image: uiImage!, position: AVCaptureDevice.Position.back, callback: { [self] barcodes, error in 224 mobileScanner.analyzeImage(image: uiImage!, position: AVCaptureDevice.Position.back, callback: { [self] barcodes, error in
224 - if error == nil && barcodes != nil {  
225 - for barcode in barcodes! {  
226 - let event: [String: Any?] = ["name": "barcode", "data": barcode.data]  
227 - barcodeHandler.publishEvent(event) 225 + if error == nil && barcodes != nil && !barcodes!.isEmpty {
  226 + let barcodesMap = barcodes!.compactMap { barcode in barcode.data }
  227 + let event: [String: Any?] = ["name": "barcode", "data": barcodesMap]
  228 + barcodeHandler.publishEvent(event)
  229 + result(true)
  230 + } else {
  231 + if error != nil {
  232 + barcodeHandler.publishEvent(["name": "error", "message": error?.localizedDescription])
228 } 233 }
229 - } else if error != nil {  
230 - barcodeHandler.publishEvent(["name": "error", "message": error?.localizedDescription]) 234 + result(false)
231 } 235 }
232 }) 236 })
233 - result(nil)  
234 } 237 }
235 } 238 }