Created
August 13, 2019 09:06
-
-
Save yushulx/e0ea1c06f24ca9131513e2a42218a631 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "BarcodeReaderPlugin.h" | |
#import <DynamsoftBarcodeReader/DynamsoftBarcodeSDK.h> | |
@implementation BarcodeReaderPlugin | |
{ | |
DynamsoftBarcodeReader *barcodeReader; | |
} | |
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar { | |
FlutterMethodChannel* channel = [FlutterMethodChannel | |
methodChannelWithName:@"barcode_reader" | |
binaryMessenger:[registrar messenger]]; | |
BarcodeReaderPlugin* instance = [[BarcodeReaderPlugin alloc] init]; | |
[registrar addMethodCallDelegate:instance channel:channel]; | |
} | |
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { | |
NSString *value = call.arguments[0]; | |
if ([@"getPlatformVersion" isEqualToString:call.method]) { | |
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]); | |
} | |
else if ([@"initLicense" isEqualToString:call.method]) { | |
barcodeReader = [[DynamsoftBarcodeReader alloc] initWithLicense:value]; | |
} | |
else if ([@"decodeFile" isEqualToString:call.method]) { | |
if (barcodeReader != nil) { | |
NSArray* results = [barcodeReader decodeFileWithName:value templateName:@"" error:nil]; | |
if(results == nil) { | |
result(@"No Barcode Detected."); | |
} | |
else { | |
iTextResult* barcode = (iTextResult*)results.firstObject; | |
if (barcode.barcodeText == nil) { | |
result(@"No Barcode Detected."); | |
} | |
else { | |
NSString* msgText = [NSString stringWithFormat:@"Format: %@, Text: %@.", barcode.barcodeFormatString, barcode.barcodeText]; | |
result(msgText); | |
} | |
} | |
} | |
else { | |
result(@"Failed to create barcode reader!"); | |
} | |
} | |
else { | |
result(FlutterMethodNotImplemented); | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment