Skip to content

Instantly share code, notes, and snippets.

@yushulx
Created August 13, 2019 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yushulx/e0ea1c06f24ca9131513e2a42218a631 to your computer and use it in GitHub Desktop.
Save yushulx/e0ea1c06f24ca9131513e2a42218a631 to your computer and use it in GitHub Desktop.
#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