From 1c34da8db99e96880382827d2dedb32b979d4e0e Mon Sep 17 00:00:00 2001 From: Benjamin Sauer Date: Wed, 10 Jan 2018 16:20:43 +0100 Subject: [PATCH] BarcodeScanPlugin.m: extracted errorHandling into seperate method --- ios/Classes/BarcodeScanPlugin.m | 14 +++++++++----- ios/Classes/BarcodeScannerViewController.m | 2 +- ios/Classes/BarcodeScannerViewControllerDelegate.h | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ios/Classes/BarcodeScanPlugin.m b/ios/Classes/BarcodeScanPlugin.m index 40ad5ac..0786757 100644 --- a/ios/Classes/BarcodeScanPlugin.m +++ b/ios/Classes/BarcodeScanPlugin.m @@ -27,13 +27,17 @@ } - (void)barcodeScannerViewController:(BarcodeScannerViewController *)controller didScanBarcodeWithResult:(NSString *)result { - if (self.result && [result isEqualToString: @"PERMISSION_NOT_GRANTED"]){ - self.result([FlutterError errorWithCode:@"PERMISSION_NOT_GRANTED" - message:nil - details:nil]); - } else if (self.result) { + if (self.result) { self.result(result); } } +- (void)barcodeScannerViewController:(BarcodeScannerViewController *)controller didScanBarcodeWithErrorCode:(NSString *)errorCode { + if (self.result){ + self.result([FlutterError errorWithCode:errorCode + message:nil + details:nil]); + } +} + @end diff --git a/ios/Classes/BarcodeScannerViewController.m b/ios/Classes/BarcodeScannerViewController.m index 114db43..0835aaf 100644 --- a/ios/Classes/BarcodeScannerViewController.m +++ b/ios/Classes/BarcodeScannerViewController.m @@ -38,7 +38,7 @@ if (success) { [self startScan]; } else { - [self.delegate barcodeScannerViewController:self didScanBarcodeWithResult:@"PERMISSION_NOT_GRANTED"]; + [self.delegate barcodeScannerViewController:self didScanBarcodeWithErrorCode:@"PERMISSION_NOT_GRANTED"]; [self dismissViewControllerAnimated:NO completion:nil]; } }]; diff --git a/ios/Classes/BarcodeScannerViewControllerDelegate.h b/ios/Classes/BarcodeScannerViewControllerDelegate.h index b5c0663..1412686 100644 --- a/ios/Classes/BarcodeScannerViewControllerDelegate.h +++ b/ios/Classes/BarcodeScannerViewControllerDelegate.h @@ -9,5 +9,6 @@ @protocol BarcodeScannerViewControllerDelegate - (void)barcodeScannerViewController:(BarcodeScannerViewController *)controller didScanBarcodeWithResult:(NSString *)result; +- (void)barcodeScannerViewController:(BarcodeScannerViewController *)controller didScanBarcodeWithErrorCode:(NSString *)errorCode; -@end \ No newline at end of file +@end