Navaron Bracke

fix dispatch queue main switch for analyze image on iOS

@@ -252,16 +252,28 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { @@ -252,16 +252,28 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin {
252 } 252 }
253 253
254 mobileScanner.analyzeImage(image: uiImage!, position: AVCaptureDevice.Position.back, callback: { [self] barcodes, error in 254 mobileScanner.analyzeImage(image: uiImage!, position: AVCaptureDevice.Position.back, callback: { [self] barcodes, error in
255 - if error == nil && barcodes != nil && !barcodes!.isEmpty { 255 + if error != nil {
  256 + barcodeHandler.publishEvent(["name": "error", "message": error?.localizedDescription])
  257 +
  258 + DispatchQueue.main.async {
  259 + result(false)
  260 + }
  261 +
  262 + return
  263 + }
  264 +
  265 + if (barcodes == nil || barcodes!.isEmpty) {
  266 + DispatchQueue.main.async {
  267 + result(false)
  268 + }
  269 + } else {
256 let barcodesMap: [Any?] = barcodes!.compactMap { barcode in barcode.data } 270 let barcodesMap: [Any?] = barcodes!.compactMap { barcode in barcode.data }
257 let event: [String: Any?] = ["name": "barcode", "data": barcodesMap] 271 let event: [String: Any?] = ["name": "barcode", "data": barcodesMap]
258 barcodeHandler.publishEvent(event) 272 barcodeHandler.publishEvent(event)
  273 +
  274 + DispatchQueue.main.async {
259 result(true) 275 result(true)
260 - } else {  
261 - if error != nil {  
262 - barcodeHandler.publishEvent(["name": "error", "message": error?.localizedDescription])  
263 } 276 }
264 - result(false)  
265 } 277 }
266 }) 278 })
267 } 279 }