diff --git a/ios/Classes/QRView.swift b/ios/Classes/QRView.swift index 971be1d..515b258 100644 --- a/ios/Classes/QRView.swift +++ b/ios/Classes/QRView.swift @@ -162,8 +162,33 @@ public class QRView:NSObject,FlutterPlatformView { default: return } - guard let stringValue = code.stringValue else { continue } - let result = ["code": stringValue, "type": typeString] + let bytes = { () -> Data? in + switch (code.descriptor) { + case let qrDescriptor as CIQRCodeDescriptor: + return qrDescriptor.errorCorrectedPayload + case let aztecDescriptor as CIAztecCodeDescriptor: + return aztecDescriptor.errorCorrectedPayload + case let pdf417Descriptor as CIPDF417CodeDescriptor: + return pdf417Descriptor.errorCorrectedPayload + case let dataMatrixDescriptor as CIDataMatrixCodeDescriptor: + return dataMatrixDescriptor.errorCorrectedPayload + default: + return nil + } + }() + let result = { () -> [String : Any]? in + guard let stringValue = code.stringValue else { + guard let safeBytes = bytes else { + return nil + } + return ["type": typeString, "rawBytes": safeBytes] + } + guard let safeBytes = bytes else { + return ["code": stringValue, "type": typeString] + } + return ["code": stringValue, "type": typeString, "rawBytes": safeBytes] + }() + guard let safeResult = result else { continue } if allowedBarcodeTypes.count == 0 || allowedBarcodeTypes.contains(code.type) { self?.channel.invokeMethod("onRecognizeQR", arguments: result) } diff --git a/lib/src/qr_code_scanner.dart b/lib/src/qr_code_scanner.dart index d7f9e5c..22876ee 100644 --- a/lib/src/qr_code_scanner.dart +++ b/lib/src/qr_code_scanner.dart @@ -187,7 +187,7 @@ class QRViewController { case 'onRecognizeQR': if (call.arguments != null) { final args = call.arguments as Map; - final code = args['code'] as String; + final code = args['code'] as String?; final rawType = args['type'] as String; // Raw bytes are only supported by Android. final rawBytes = args['rawBytes'] as List?; diff --git a/lib/src/types/barcode.dart b/lib/src/types/barcode.dart index 9627a9f..c8c3105 100644 --- a/lib/src/types/barcode.dart +++ b/lib/src/types/barcode.dart @@ -2,15 +2,15 @@ import 'barcode_format.dart'; /// The [Barcode] object holds information about the barcode or qr code. /// -/// [code] is the content of the barcode. +/// [code] is the string-content of the barcode. /// [format] displays which type the code is. -/// Only for Android, [rawBytes] gives a list of bytes of the result. +/// Only for Android and iOS, [rawBytes] gives a list of bytes of the result. class Barcode { Barcode(this.code, this.format, this.rawBytes); - final String code; + final String? code; final BarcodeFormat format; - /// Raw bytes are only supported by Android. + /// Raw bytes are only supported by Android and iOS. final List? rawBytes; }