BarcodeScanPlugin.m: extracted errorHandling into seperate method

This commit is contained in:
Benjamin Sauer 2018-01-10 16:20:43 +01:00
parent 616b286a5c
commit 1c34da8db9
3 changed files with 12 additions and 7 deletions

View File

@ -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

View File

@ -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];
}
}];

View File

@ -9,5 +9,6 @@
@protocol BarcodeScannerViewControllerDelegate <NSObject>
- (void)barcodeScannerViewController:(BarcodeScannerViewController *)controller didScanBarcodeWithResult:(NSString *)result;
- (void)barcodeScannerViewController:(BarcodeScannerViewController *)controller didScanBarcodeWithErrorCode:(NSString *)errorCode;
@end
@end