Committed by
GitHub
Merge pull request #512 from juliansteenbakker/bug/fix-analyze-image
fix: fixed barcodes not found on analyzeImage
Showing
1 changed file
with
9 additions
and
6 deletions
| @@ -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] | 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] | ||
| 227 | barcodeHandler.publishEvent(event) | 228 | barcodeHandler.publishEvent(event) |
| 228 | - } | ||
| 229 | - } else if error != nil { | 229 | + result(true) |
| 230 | + } else { | ||
| 231 | + if error != nil { | ||
| 230 | barcodeHandler.publishEvent(["name": "error", "message": error?.localizedDescription]) | 232 | barcodeHandler.publishEvent(["name": "error", "message": error?.localizedDescription]) |
| 231 | } | 233 | } |
| 234 | + result(false) | ||
| 235 | + } | ||
| 232 | }) | 236 | }) |
| 233 | - result(nil) | ||
| 234 | } | 237 | } |
| 235 | } | 238 | } |
-
Please register or login to post a comment