From f71f38491f9986f7d182cfb7277106279325dde8 Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Wed, 3 Nov 2021 11:39:48 +0100 Subject: [PATCH] bug: fix crash because of unsupported iOS version --- ios/Classes/QRView.swift | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/ios/Classes/QRView.swift b/ios/Classes/QRView.swift index e91caf88..f37c6769 100644 --- a/ios/Classes/QRView.swift +++ b/ios/Classes/QRView.swift @@ -165,16 +165,20 @@ public class QRView:NSObject,FlutterPlatformView { return } 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: + if #available(iOS 11.0, *) { + 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 + } + } else { return nil } }() @@ -190,7 +194,7 @@ public class QRView:NSObject,FlutterPlatformView { } return ["code": stringValue, "type": typeString, "rawBytes": safeBytes] }() - guard let safeResult = result else { continue } + guard result != nil else { continue } if allowedBarcodeTypes.count == 0 || allowedBarcodeTypes.contains(code.type) { self?.channel.invokeMethod("onRecognizeQR", arguments: result) }