diff --git a/example/RNExampleApp/android/app/build.gradle b/example/RNExampleApp/android/app/build.gradle index 9711e11..c816b7c 100644 --- a/example/RNExampleApp/android/app/build.gradle +++ b/example/RNExampleApp/android/app/build.gradle @@ -87,7 +87,7 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 5 - versionName "53.2.0" + versionName "53.3.0" multiDexEnabled true buildConfigField("boolean", "REACT_NATIVE_UNSTABLE_USE_RUNTIME_SCHEDULER_ALWAYS", (findProperty("reactNative.unstable_useRuntimeSchedulerAlways") ?: true).toString()) diff --git a/example/RNExampleApp/ios/RNExampleApp.xcodeproj/project.pbxproj b/example/RNExampleApp/ios/RNExampleApp.xcodeproj/project.pbxproj index ca514d5..05b7d29 100644 --- a/example/RNExampleApp/ios/RNExampleApp.xcodeproj/project.pbxproj +++ b/example/RNExampleApp/ios/RNExampleApp.xcodeproj/project.pbxproj @@ -272,7 +272,7 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-RNExampleApp/Pods-RNExampleApp-resources.sh", "${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle", - "${PODS_ROOT}/Anyline/AnylineSDK_iOS_53.2.0/Framework/AnylineResources.bundle", + "${PODS_ROOT}/Anyline/AnylineSDK_iOS_53.3.0/Framework/AnylineResources.bundle", ); name = "[CP] Copy Pods Resources"; outputPaths = ( @@ -347,7 +347,7 @@ INFOPLIST_FILE = RNExampleApp/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 53.2.0; + MARKETING_VERSION = 53.3.0; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -380,7 +380,7 @@ INFOPLIST_FILE = RNExampleApp/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 53.2.0; + MARKETING_VERSION = 53.3.0; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", diff --git a/example/RNExampleApp/package.json b/example/RNExampleApp/package.json index 3190b06..b177c64 100644 --- a/example/RNExampleApp/package.json +++ b/example/RNExampleApp/package.json @@ -1,6 +1,6 @@ { "name": "react-native-example-app", - "version": "53.2.0", + "version": "53.3.0", "private": true, "scripts": { "initProject": "yarn add expo && yarn add ../../plugin", diff --git a/plugin/android/build.gradle b/plugin/android/build.gradle index 482c932..009aa40 100755 --- a/plugin/android/build.gradle +++ b/plugin/android/build.gradle @@ -61,7 +61,7 @@ repositories { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation 'io.anyline:anylinesdk:53.2.0' + implementation 'io.anyline:anylinesdk:53.3.0' implementation "com.facebook.react:react-native:+" implementation("com.google.android.material:material:1.9.0") implementation 'androidx.multidex:multidex:2.0.1' diff --git a/plugin/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java b/plugin/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java index 260ee94..62da740 100755 --- a/plugin/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java +++ b/plugin/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java @@ -35,6 +35,7 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor public static final String REACT_CLASS = "AnylineSDKPlugin"; public static final String EXTRA_LICENSE_KEY = "EXTRA_LICENSE_KEY"; public static final String EXTRA_CONFIG_JSON = "EXTRA_CONFIG_JSON"; + public static final String EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS = "EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS"; public static final String EXTRA_SCAN_MODE = "EXTRA_SCAN_MODE"; public static final String EXTRA_ERROR_MESSAGE = "EXTRA_ERROR_MESSAGE"; public static final String EXTRA_OCR_CONFIG_JSON = "EXTRA_OCR_CONFIG_JSON"; @@ -53,6 +54,7 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor private Promise promise; private String returnMethod; private String config; + private String scanViewInitializationParameters; private AssetContextJsonParser assetContextJsonParser; private static WrapperConfig wrapperConfig; @@ -175,10 +177,16 @@ public void resetUpdate() { @ReactMethod public void setup(String config, String scanMode, Callback onResultReact, Callback onErrorReact) { + setupWithInitializationParameters(null, config, scanMode, onResultReact, onErrorReact); + } + + @ReactMethod + public void setupWithInitializationParameters(String initializationParameters, String config, String scanMode, Callback onResultReact, Callback onErrorReact) { onResultCallback = onResultReact; onErrorCallback = onErrorReact; this.returnMethod = "callback"; this.config = config; + this.scanViewInitializationParameters = initializationParameters; routeScanMode(scanMode); } @@ -226,9 +234,14 @@ public void exportCachedEvents(final Promise promise) { @ReactMethod public void setupPromise(String config, String scanMode, final Promise promise) { + setupPromiseWithInitializationParameters(null, config, scanMode, promise); + } + @ReactMethod + public void setupPromiseWithInitializationParameters(String initializationParameters, String config, String scanMode, final Promise promise) { this.promise = promise; this.returnMethod = "promise"; this.config = config; + this.scanViewInitializationParameters = initializationParameters; routeScanMode(scanMode); } @@ -281,13 +294,14 @@ private void scan() throws LicenseException, JSONException { if (optionsJSONObject != null) { intent.putExtra( - EXTRA_ENABLE_BARCODE_SCANNING, - optionsJSONObject.optBoolean("nativeBarcodeEnabled", false) + EXTRA_ENABLE_BARCODE_SCANNING, + optionsJSONObject.optBoolean("nativeBarcodeEnabled", false) ); } intent.putExtra(EXTRA_LICENSE_KEY, license); intent.putExtra(EXTRA_CONFIG_JSON, configObject.toString()); + intent.putExtra(EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS, scanViewInitializationParameters); ResultReporter.setListener(this); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/plugin/android/src/main/java/com/anyline/reactnative/ScanActivity.java b/plugin/android/src/main/java/com/anyline/reactnative/ScanActivity.java index 283008a..b52742b 100644 --- a/plugin/android/src/main/java/com/anyline/reactnative/ScanActivity.java +++ b/plugin/android/src/main/java/com/anyline/reactnative/ScanActivity.java @@ -1,8 +1,10 @@ package com.anyline.reactnative; import static com.anyline.reactnative.AnylineSDKPlugin.EXTRA_CONFIG_JSON; +import static com.anyline.reactnative.AnylineSDKPlugin.EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS; import static com.anyline.reactnative.AnylineSDKPlugin.EXTRA_ERROR_MESSAGE; import static com.anyline.reactnative.AnylineSDKPlugin.RESULT_ERROR; +import static io.anyline2.sdk.extension.ScanViewInitializationParametersExtensionKt.getScanViewInitializationParametersFromJsonObject; import android.content.Intent; import android.content.pm.ActivityInfo; @@ -29,6 +31,7 @@ import java.util.Timer; import java.util.TimerTask; +import io.anyline.plugin.config.ScanViewInitializationParameters; import io.anyline2.ScanResult; import io.anyline2.view.ScanView; import io.anyline2.viewplugin.ScanViewPlugin; @@ -98,7 +101,17 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setupChangeOrientationButton(configJSON); setupCustomUIFeedback(configJSON); - scanView.init(configJSON); + String initializationParametersString = getIntent().getStringExtra(EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS); + if (initializationParametersString != null) { + ScanViewInitializationParameters scanViewInitializationParameters = + getScanViewInitializationParametersFromJsonObject( + this, + new JSONObject(initializationParametersString)); + scanView.init(configJSON, scanViewInitializationParameters); + } + else { + scanView.init(configJSON); + } ViewPluginBase viewPluginBase = scanView.getScanViewPlugin(); diff --git a/plugin/ios/ALNFCScanViewController.h b/plugin/ios/ALNFCScanViewController.h index 6f54cee..22938f1 100644 --- a/plugin/ios/ALNFCScanViewController.h +++ b/plugin/ios/ALNFCScanViewController.h @@ -8,6 +8,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithLicensekey:(NSString *)licensekey configuration:(NSDictionary *)anylineConfig uiConfig:(ALJSONUIConfiguration *)uiConfig + initializationParamsStr:(NSString *)initializationParamsStr finished:(ALPluginCallback)callback; @end diff --git a/plugin/ios/ALNFCScanViewController.m b/plugin/ios/ALNFCScanViewController.m index ea1e1fb..b079a9c 100644 --- a/plugin/ios/ALNFCScanViewController.m +++ b/plugin/ios/ALNFCScanViewController.m @@ -47,6 +47,7 @@ @interface ALNFCScanViewController () <ALNFCDetectorDelegate, ALScanPluginDelega // JPEG compression quality 0-100 @property (nonatomic, assign) NSUInteger quality; +@property (nonatomic, nullable) NSString *initializationParamsStr; @end @@ -56,13 +57,14 @@ @implementation ALNFCScanViewController - (instancetype)initWithLicensekey:(NSString *)licensekey configuration:(NSDictionary *)anylineConfig uiConfig:(ALJSONUIConfiguration *)uiConfig + initializationParamsStr:(NSString *)initializationParamsStr finished:(ALPluginCallback)callback { if (self = [super init]) { _licenseKey = licensekey; _callback = callback; _config = anylineConfig; _uiConfig = uiConfig; - + _initializationParamsStr = initializationParamsStr; self.quality = 90; } return self; @@ -95,12 +97,20 @@ - (void)viewDidLoad { return; } + ALScanViewInitializationParameters *initializationParams = nil; + if(_initializationParamsStr){ + initializationParams= [ALScanViewInitializationParameters withJSONString:_initializationParamsStr error:&error]; + } + [self.view addSubview:self.scanView]; self.resultDict = [[NSMutableDictionary alloc] init]; self.detectedBarcodes = [NSMutableArray array]; - self.scanView = [ALScanViewFactory withJSONDictionary:self.config delegate:self error:&error]; + self.scanView = [ALScanViewFactory withJSONDictionary:self.config + initializationParams:initializationParams + delegate:self + error:&error]; self.scanView.delegate = self; [self configureMRZPlugin]; diff --git a/plugin/ios/ALPluginHelper.h b/plugin/ios/ALPluginHelper.h index 33c5b9e..af503db 100644 --- a/plugin/ios/ALPluginHelper.h +++ b/plugin/ios/ALPluginHelper.h @@ -10,7 +10,7 @@ typedef void (^ALPluginCallback)(NSDictionary * _Nullable callbackObj, NSError * @interface ALPluginHelper : NSObject -+ (void)startScan:(NSDictionary *)config finished:(ALPluginCallback)callback; ++ (void)startScan:(NSDictionary *)config initializationParamsStr:(NSString *)initializationParamsStr finished:(ALPluginCallback)callback; + (NSString *)saveImageToFileSystem:(UIImage *)image; diff --git a/plugin/ios/ALPluginHelper.m b/plugin/ios/ALPluginHelper.m index c5c503f..b8dd67d 100644 --- a/plugin/ios/ALPluginHelper.m +++ b/plugin/ios/ALPluginHelper.m @@ -10,7 +10,7 @@ @implementation ALPluginHelper #pragma mark - Launch Anyline -+ (void)startScan:(NSDictionary *)config finished:(ALPluginCallback)callback { ++ (void)startScan:(NSDictionary *)config initializationParamsStr:(NSString *)initializationParamsStr finished:(ALPluginCallback)callback { NSDictionary *pluginConf = config; @@ -35,7 +35,8 @@ + (void)startScan:(NSDictionary *)config finished:(ALPluginCallback)callback { ALNFCScanViewController *nfcScanViewController = [[ALNFCScanViewController alloc] initWithLicensekey:licenseKey configuration:pluginConf uiConfig:jsonUIConf - finished:callback]; + initializationParamsStr:initializationParamsStr + finished:callback]; if (nfcScanViewController != nil) { [nfcScanViewController setModalPresentationStyle:UIModalPresentationFullScreen]; [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:nfcScanViewController @@ -50,6 +51,7 @@ + (void)startScan:(NSDictionary *)config finished:(ALPluginCallback)callback { ALPluginScanViewController *pluginScanViewController = [[ALPluginScanViewController alloc] initWithLicensekey:licenseKey configuration:pluginConf uiConfiguration:jsonUIConf + initializationParamsStr:initializationParamsStr finished:callback]; if ([pluginConf valueForKey:@"quality"]){ diff --git a/plugin/ios/ALPluginScanViewController.h b/plugin/ios/ALPluginScanViewController.h index f127638..2eefa3f 100644 --- a/plugin/ios/ALPluginScanViewController.h +++ b/plugin/ios/ALPluginScanViewController.h @@ -10,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithLicensekey:(NSString *)licenseKey configuration:(NSDictionary *)config uiConfiguration:(ALJSONUIConfiguration *)JSONUIConfig + initializationParamsStr:(NSString *)initializationParamsStr finished:(ALPluginCallback)callback; @end diff --git a/plugin/ios/ALPluginScanViewController.m b/plugin/ios/ALPluginScanViewController.m index f9f0273..50ef1fe 100644 --- a/plugin/ios/ALPluginScanViewController.m +++ b/plugin/ios/ALPluginScanViewController.m @@ -37,6 +37,8 @@ @interface ALPluginScanViewController () <ALScanPluginDelegate, ALViewPluginComp @property (nonatomic, strong) NSError *scanViewError; +@property (nonatomic, nullable) NSString *initializationParamsStr; + @end @@ -49,6 +51,7 @@ - (void)dealloc { - (instancetype)initWithLicensekey:(NSString *)licenseKey configuration:(NSDictionary *)config uiConfiguration:(ALJSONUIConfiguration *)JSONUIConfig + initializationParamsStr:(NSString *)initializationParamsStr finished:(ALPluginCallback)callback { if (self = [super init]) { @@ -56,7 +59,8 @@ - (instancetype)initWithLicensekey:(NSString *)licenseKey _callback = callback; _config = config; _uiConfig = JSONUIConfig; - + _initializationParamsStr = initializationParamsStr; + self.quality = 100; } return self; @@ -79,7 +83,18 @@ - (void)viewDidLoad { } } + ALScanViewInitializationParameters *initializationParams = nil; + if(![self isStringEmpty:_initializationParamsStr]){ + initializationParams = [ALScanViewInitializationParameters withJSONString: _initializationParamsStr error:&error]; + } + + if ([self showErrorAlertIfNeeded:error]) { + self.scanViewError = error; + return; + } + self.scanView = [ALScanViewFactory withJSONDictionary:self.config + initializationParams:initializationParams delegate:self error:&error]; @@ -434,6 +449,13 @@ - (BOOL)segmentModesAreValid { return YES; } +-(BOOL)isStringEmpty:(NSString *)str { + if(str == nil || [str isKindOfClass:[NSNull class]] || str.length==0) { + return YES; + } + return NO; +} + // MARK: - Miscellaneous - (BOOL)showErrorAlertIfNeeded:(NSError *)error { diff --git a/plugin/ios/AnylineReact.podspec b/plugin/ios/AnylineReact.podspec index 5307181..a688b35 100644 --- a/plugin/ios/AnylineReact.podspec +++ b/plugin/ios/AnylineReact.podspec @@ -18,7 +18,7 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/Anyline/anyline-ocr-react-native-module.git", :tag => "#{s.version}" } s.source_files = "*.{h,m}" - s.dependency "Anyline", "53.2.0" + s.dependency "Anyline", "53.3.0" s.dependency "React" -end \ No newline at end of file +end diff --git a/plugin/ios/AnylineSDKPlugin.m b/plugin/ios/AnylineSDKPlugin.m index d51ce85..71a2416 100644 --- a/plugin/ios/AnylineSDKPlugin.m +++ b/plugin/ios/AnylineSDKPlugin.m @@ -27,6 +27,8 @@ @interface AnylineSDKPlugin() @property (nonatomic, copy) NSString *returnMethod; +@property (nonatomic, copy) NSString *initializationParamsStr; + @end @@ -46,15 +48,19 @@ - (UIView *)view { self.onErrorCallback = onError; self.returnMethod = @"callback"; self.config = config; - [self initView:scanMode]; + [self initView:scanMode initializationParamsStr:nil]; } RCT_EXPORT_METHOD(setup:(NSString *)config scanMode:(NSString *)scanMode onResultCallback:(RCTResponseSenderBlock)onResult onErrorCallback:(RCTResponseSenderBlock)onError) { + [self setupWithInitializationParameters:nil config:config scanMode:scanMode onResultCallback:onResult onErrorCallback:onError]; +} + +RCT_EXPORT_METHOD(setupWithInitializationParameters:(NSString * _Nullable)initializationParametersStr config:(NSString *)config scanMode:(NSString *)scanMode onResultCallback:(RCTResponseSenderBlock)onResult onErrorCallback:(RCTResponseSenderBlock)onError) { self.onResultCallback = onResult; self.onErrorCallback = onError; self.returnMethod = @"callback"; self.config = config; - [self initView:scanMode]; + [self initView:scanMode initializationParamsStr:initializationParametersStr]; } RCT_EXPORT_METHOD(setupAnylineSDK:(NSString *)licenseKey @@ -92,11 +98,16 @@ - (UIView *)view { } RCT_EXPORT_METHOD(setupPromise:(NSString *)config scanMode:(NSString *)scanMode resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { + [self setupPromiseWithInitializationParameters:nil config:config scanMode:scanMode resolver:resolve rejecter:reject]; +} + +RCT_EXPORT_METHOD(setupPromiseWithInitializationParameters:(NSString * _Nullable)initializationParametersStr config:(NSString *)configStr scanMode:(NSString *)scanMode resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { _resolveBlock = resolve; _rejectBlock = reject; self.returnMethod = @"promise"; - self.config = config; - [self initView:scanMode]; + self.config = configStr; + self.initializationParamsStr = initializationParametersStr; + [self initView:scanMode initializationParamsStr:self.initializationParamsStr]; } RCT_EXPORT_METHOD(getSDKVersion:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { @@ -134,7 +145,7 @@ - (UIView *)view { } -- (void)initView:(NSString *)scanMode { +- (void)initView:(NSString *)scanMode initializationParamsStr:(NSString * _Nullable)initializationParamsStr { NSData *data = [self.config dataUsingEncoding:NSUTF8StringEncoding]; if (!data) { [NSException raise:@"Config could not be loaded from disk" format:@"Config could not be loaded from disk"]; @@ -172,6 +183,7 @@ - (void)initView:(NSString *)scanMode { ALNFCScanViewController *nfcScanViewController = [[ALNFCScanViewController alloc] initWithLicensekey:self.appKey configuration:dictionary uiConfig:self.jsonUIConf + initializationParamsStr:initializationParamsStr finished:^(NSDictionary * _Nullable callbackObj, NSError * _Nullable error) { [self returnCallback:callbackObj andError:error]; }]; @@ -191,7 +203,9 @@ - (void)initView:(NSString *)scanMode { ALPluginScanViewController *pluginScanViewController = [[ALPluginScanViewController alloc] initWithLicensekey:self.appKey configuration:dictionary - uiConfiguration:self.jsonUIConf finished:^(NSDictionary * _Nullable callbackObj, NSError * _Nullable error) { + uiConfiguration:self.jsonUIConf + initializationParamsStr:initializationParamsStr + finished:^(NSDictionary * _Nullable callbackObj, NSError * _Nullable error) { [self returnCallback:callbackObj andError:error]; }]; @@ -204,7 +218,9 @@ - (void)initView:(NSString *)scanMode { ALPluginScanViewController *pluginScanViewController = [[ALPluginScanViewController alloc] initWithLicensekey:self.appKey configuration:dictionary - uiConfiguration:self.jsonUIConf finished:^(NSDictionary * _Nullable callbackObj, NSError * _Nullable error) { + uiConfiguration:self.jsonUIConf + initializationParamsStr:initializationParamsStr + finished:^(NSDictionary * _Nullable callbackObj, NSError * _Nullable error) { [self returnCallback:callbackObj andError:error]; }]; diff --git a/plugin/package.json b/plugin/package.json index 9c79d84..c4ea4a6 100644 --- a/plugin/package.json +++ b/plugin/package.json @@ -1,6 +1,6 @@ { - "_from": "anyline-ocr-react-native-module@^53.2.0", - "_id": "anyline-ocr-react-native-module@^53.2.0", + "_from": "anyline-ocr-react-native-module@^53.3.0", + "_id": "anyline-ocr-react-native-module@^53.3.0", "_inBundle": false, "_integrity": "sha512-BGi9zNkSsoxXywDBIqzgBRvKUBniQOJHDKBrozZubKthZNRBAj8Ry5tW0Me0yLXt/fauME//hbC0wsenfPJZqw==", "_location": "/anyline-ocr-react-native-module", @@ -8,19 +8,19 @@ "_requested": { "type": "range", "registry": true, - "raw": "anyline-ocr-react-native-module@^53.2.0", + "raw": "anyline-ocr-react-native-module@^53.3.0", "name": "anyline-ocr-react-native-module", "escapedName": "anyline-ocr-react-native-module", - "rawSpec": "^53.2.0", + "rawSpec": "^53.3.0", "saveSpec": null, - "fetchSpec": "^53.2.0" + "fetchSpec": "^53.3.0" }, "_requiredBy": [ "/" ], - "_resolved": "https://registry.npmjs.org/anyline-ocr-react-native-module/-/anyline-ocr-react-native-module-53.2.0.tgz", + "_resolved": "https://registry.npmjs.org/anyline-ocr-react-native-module/-/anyline-ocr-react-native-module-53.3.0.tgz", "_shasum": "bacbcd260cc662244f59393ed81a6edba009b52c", - "_spec": "anyline-ocr-react-native-module@^53.2.0", + "_spec": "anyline-ocr-react-native-module@^53.3.0", "_where": "/Users/amiransari/Projects/anyline-ocr-react-native-module1/example/RNExampleApp", "bugs": { "url": "https://github.com/Anyline/anyline-ocr-react-native-module/issues" @@ -47,5 +47,5 @@ "type": "git", "url": "git+https://github.com/Anyline/anyline-ocr-react-native-module.git" }, - "version": "53.2.0" + "version": "53.3.0" }