flutter_barcode_reader/ios/Classes/BarcodeScanPlugin.m

46 lines
1.9 KiB
Mathematica
Raw Normal View History

2017-10-30 01:05:11 +08:00
#import "BarcodeScanPlugin.h"
#import "BarcodeScannerViewController.h"
2017-10-30 01:05:11 +08:00
@implementation BarcodeScanPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"de.mintware.barcode_scan"
binaryMessenger:registrar.messenger];
BarcodeScanPlugin *instance = [BarcodeScanPlugin new];
instance.hostViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
[registrar addMethodCallDelegate:instance channel:channel];
2017-10-30 01:05:11 +08:00
}
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
if ([@"scan" isEqualToString:call.method]) {
self.result = result;
[self showBarcodeView];
} else {
result(FlutterMethodNotImplemented);
}
}
- (void)showBarcodeView {
BarcodeScannerViewController *scannerViewController = [[BarcodeScannerViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:scannerViewController];
if (@available(iOS 13.0, *)) {
[navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
}
scannerViewController.delegate = self;
[self.hostViewController presentViewController:navigationController animated:NO completion:nil];
}
- (void)barcodeScannerViewController:(BarcodeScannerViewController *)controller didScanBarcodeWithResult:(NSString *)result {
if (self.result) {
self.result(result);
}
}
- (void)barcodeScannerViewController:(BarcodeScannerViewController *)controller didFailWithErrorCode:(NSString *)errorCode {
if (self.result){
self.result([FlutterError errorWithCode:errorCode
message:nil
details:nil]);
}
}
2017-10-30 01:05:11 +08:00
@end