anyline-ocr-react-native-module 55.2.1 → 55.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/AnylineReact.podspec +1 -1
  2. package/android/build.gradle +1 -3
  3. package/android/src/main/AndroidManifest.xml +1 -3
  4. package/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java +248 -254
  5. package/index.js +1 -15
  6. package/ios/AnylineSDKPlugin.h +4 -4
  7. package/ios/AnylineSDKPlugin.m +278 -211
  8. package/package.json +1 -1
  9. package/android/.gradle/7.6/checksums/checksums.lock +0 -0
  10. package/android/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock +0 -0
  11. package/android/.gradle/7.6/dependencies-accessors/gc.properties +0 -0
  12. package/android/.gradle/7.6/fileChanges/last-build.bin +0 -0
  13. package/android/.gradle/7.6/fileHashes/fileHashes.lock +0 -0
  14. package/android/.gradle/7.6/gc.properties +0 -0
  15. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  16. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  17. package/android/.gradle/vcs-1/gc.properties +0 -0
  18. package/android/src/main/java/com/anyline/reactnative/FeedbackConfig.java +0 -59
  19. package/android/src/main/java/com/anyline/reactnative/ImageTextConfig.java +0 -49
  20. package/android/src/main/java/com/anyline/reactnative/InstructionConfig.java +0 -20
  21. package/android/src/main/java/com/anyline/reactnative/Offset.java +0 -21
  22. package/android/src/main/java/com/anyline/reactnative/RotateButtonConfig.java +0 -32
  23. package/android/src/main/java/com/anyline/reactnative/ScanActivity.java +0 -426
  24. package/android/src/main/java/com/anyline/reactnative/updateAsset/AnylineUpdateDelegateImpl.java +0 -50
  25. package/android/src/main/java/com/anyline/reactnative/updateAsset/AssetContextJsonParser.java +0 -28
  26. package/android/src/main/res/drawable/rotate_screen_background.xml +0 -18
  27. package/android/src/main/res/drawable/rotate_screen_white.png +0 -0
  28. package/android/src/main/res/drawable-hdpi/ic_flash_auto.png +0 -0
  29. package/android/src/main/res/drawable-hdpi/ic_flash_off.png +0 -0
  30. package/android/src/main/res/drawable-hdpi/ic_flash_on.png +0 -0
  31. package/android/src/main/res/drawable-mdpi/ic_flash_auto.png +0 -0
  32. package/android/src/main/res/drawable-mdpi/ic_flash_off.png +0 -0
  33. package/android/src/main/res/drawable-mdpi/ic_flash_on.png +0 -0
  34. package/android/src/main/res/drawable-xhdpi/ic_flash_auto.png +0 -0
  35. package/android/src/main/res/drawable-xhdpi/ic_flash_off.png +0 -0
  36. package/android/src/main/res/drawable-xhdpi/ic_flash_on.png +0 -0
  37. package/android/src/main/res/drawable-xxhdpi/ic_flash_auto.png +0 -0
  38. package/android/src/main/res/drawable-xxhdpi/ic_flash_off.png +0 -0
  39. package/android/src/main/res/drawable-xxhdpi/ic_flash_on.png +0 -0
  40. package/android/src/main/res/drawable-xxxhdpi/ic_flash_auto.png +0 -0
  41. package/android/src/main/res/drawable-xxxhdpi/ic_flash_off.png +0 -0
  42. package/android/src/main/res/drawable-xxxhdpi/ic_flash_on.png +0 -0
  43. package/android/src/main/res/layout/activity_scan.xml +0 -93
  44. package/ios/ALJsonUIConfiguration.h +0 -54
  45. package/ios/ALJsonUIConfiguration.m +0 -251
  46. package/ios/ALPluginHelper.h +0 -48
  47. package/ios/ALPluginHelper.m +0 -332
  48. package/ios/ALPluginScanViewController.h +0 -18
  49. package/ios/ALPluginScanViewController.m +0 -476
  50. package/ios/ALRoundedView.h +0 -25
  51. package/ios/ALRoundedView.m +0 -107
package/index.js CHANGED
@@ -1,25 +1,11 @@
1
1
  import {NativeModules} from 'react-native';
2
2
  import {version as pluginVersion} from './package.json';
3
3
 
4
- const Buffer = require('buffer/').Buffer;
5
-
6
4
  const AnylineOCR = NativeModules.AnylineSDKPlugin;
7
5
 
8
6
  export default AnylineOCR;
9
7
 
10
- /**
11
- * Decrypts the License and returns the date till it's valid
12
- *
13
- * @param License
14
- */
15
- export const getLicenseExpiryDate = (License) => {
16
- const licenseString = Buffer.from(License, 'base64').toString('ascii');
17
- const licenseJsonString = licenseString.substr(0, licenseString.lastIndexOf('}')+1);
18
- const licenseJson = JSON.parse(licenseJsonString);
19
- return licenseJson.valid;
20
- };
21
-
22
- AnylineOCR.setPluginVersion(pluginVersion);
8
+ AnylineOCR.setupWrapperSession(pluginVersion);
23
9
 
24
10
  AnylineOCR.getPluginVersion = () => {
25
11
  return pluginVersion;
@@ -1,9 +1,9 @@
1
1
 
2
2
  #import <Foundation/Foundation.h>
3
- #import "RCTBridgeModule.h"
3
+ #import <Anyline/Anyline.h>
4
+ #import <React/RCTEventEmitter.h>
5
+ #import <React/RCTBridgeModule.h>
4
6
 
5
- extern ALWrapperConfig *wrapperConfig;
6
-
7
- @interface AnylineSDKPlugin : NSObject <RCTBridgeModule>
7
+ @interface AnylineSDKPlugin : RCTEventEmitter <RCTBridgeModule, ALWrapperSessionClientDelegate>
8
8
 
9
9
  @end
@@ -1,80 +1,81 @@
1
- #import <Anyline/Anyline.h>
1
+
2
+ #import <React/RCTEventEmitter.h>
3
+ #import <React/RCTBridge.h>
2
4
  #import "AnylineSDKPlugin.h"
3
- #import "ALJsonUIConfiguration.h"
4
- #import "ALPluginScanViewController.h"
5
- #import "ALPluginHelper.h"
5
+ #import "RCTUtils.h"
6
6
 
7
- // We're creating a static variable to retain the SDK instance in order to prevent crashes due to memory clean up.
8
- static AnylineSDK *anylineSDK;
7
+ // Static instance to retain the ALWrapperSessionProvider instance
8
+ static ALWrapperSessionProvider *_wrapperSessionProvider;
9
9
  // We're creating a static variable to store the last license used to initialize the SDK
10
10
  static NSString *license;
11
11
 
12
- ALWrapperConfig *wrapperConfig = nil;
12
+ static NSString *scanViewConfigPathString;
13
13
 
14
14
  @interface AnylineSDKPlugin()
15
15
 
16
16
  @property (nonatomic, copy) NSString *callbackId;
17
- @property (nonatomic, assign) BOOL nativeBarcodeScanning;
18
- @property (nonatomic, strong) NSDictionary *jsonConfigDictionary;
19
- @property (nonatomic, strong) NSDictionary *ocrConfigDict;
20
- @property (nonatomic, strong) ALJSONUIConfiguration *jsonUIConf;
21
-
22
- @property (nonatomic, strong) RCTResponseSenderBlock onResultCallback;
23
- @property (nonatomic, strong) RCTResponseSenderBlock onErrorCallback;
24
17
 
25
18
  @property (nonatomic, copy) NSString *config;
26
19
 
27
20
  @property (nonatomic, copy) NSString *returnMethod;
28
21
 
29
- @property (nonatomic, copy) NSString *initializationParamsStr;
22
+ @property (nonatomic, strong) RCTPromiseResolveBlock wrapperSessionSdkInitializationResponsePromiseResolve;
23
+ @property (nonatomic, strong) RCTPromiseRejectBlock wrapperSessionSdkInitializationResponsePromiseReject;
24
+
25
+ @property (nonatomic, strong) RCTPromiseResolveBlock wrapperSessionScanResponsePromiseResolve;
26
+ @property (nonatomic, strong) RCTPromiseRejectBlock wrapperSessionScanResponsePromiseReject;
27
+
28
+ @property (nonatomic, strong) RCTResponseSenderBlock scanResponseResultCallback;
29
+ @property (nonatomic, strong) RCTResponseSenderBlock scanResponseErrorCallback;
30
+
31
+ @property (nonatomic, strong) RCTPromiseResolveBlock wrapperSessionExportCachedEventsPromiseResolve;
32
+ @property (nonatomic, strong) RCTPromiseRejectBlock wrapperSessionExportCachedEventsPromiseReject;
33
+
34
+ @property (nonatomic, strong) RCTResponseSenderBlock reportCorrectedResultResponseCallback;
35
+ @property (nonatomic, strong) RCTResponseSenderBlock reportCorrectedResultErrorCallback;
30
36
 
31
37
  @end
32
38
 
33
39
 
34
40
  @implementation AnylineSDKPlugin {
35
- RCTPromiseResolveBlock _resolveBlock;
36
- RCTPromiseRejectBlock _rejectBlock;
37
- }
38
-
39
- + (BOOL)isInitializedWithLicenseKey:(NSString *)requestedLicense {
40
- return (license && [AnylineSDK isInitialized] && [license isEqualToString:requestedLicense]);
41
+ NSMutableArray<NSString *> *supportedRTCEventsArray;
41
42
  }
42
43
 
43
44
  - (instancetype)init {
44
- self = [super init];
45
+ self = [super initWithDisabledObservation];
45
46
  if (self) {
46
- if (!anylineSDK) {
47
- // Initialize the anylineSDK static variable
48
- anylineSDK = [[AnylineSDK alloc] init];
47
+ if (!_wrapperSessionProvider) {
48
+ // Initialize the wrapperSessionProvider static variable
49
+ _wrapperSessionProvider = [[ALWrapperSessionProvider alloc] init];
49
50
  }
51
+ supportedRTCEventsArray = [NSMutableArray array];
50
52
  }
51
53
  return self;
52
54
  }
53
55
 
56
+ + (BOOL)isInitializedWithLicenseKey:(NSString *)requestedLicense {
57
+ ALWrapperSessionSDKInitializationResponse *currentSdkInitializationResponse = [ALWrapperSessionProvider getCurrentSdkInitializationResponse];
58
+ return (license
59
+ && currentSdkInitializationResponse.initialized != 0
60
+ && [license isEqualToString:requestedLicense]);
61
+ }
62
+
54
63
  RCT_EXPORT_MODULE();
64
+
55
65
  - (UIView *)view {
56
66
  return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
57
67
  }
58
68
 
59
- // Deprecated
60
- RCT_EXPORT_METHOD(setupScanViewWithConfigJson:(NSString *)config scanMode:(NSString *)scanMode onResultCallback:(RCTResponseSenderBlock)onResult onErrorCallback:(RCTResponseSenderBlock)onError) {
61
- self.onResultCallback = onResult;
62
- self.onErrorCallback = onError;
63
- self.returnMethod = @"callback";
64
- self.config = config;
65
- [self initView:scanMode initializationParamsStr:nil];
69
+ RCT_EXPORT_METHOD(getSDKVersion:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
70
+ resolve(AnylineSDK.versionNumber);
66
71
  }
67
72
 
68
- RCT_EXPORT_METHOD(setup:(NSString *)config scanMode:(NSString *)scanMode onResultCallback:(RCTResponseSenderBlock)onResult onErrorCallback:(RCTResponseSenderBlock)onError) {
69
- [self setupWithInitializationParameters:nil config:config scanMode:scanMode onResultCallback:onResult onErrorCallback:onError];
73
+ RCT_EXPORT_METHOD(setupWrapperSession:(NSString *)pluginVersion) {
74
+ [self setupWrapperSessionWithPluginVersion:pluginVersion];
70
75
  }
71
76
 
72
- RCT_EXPORT_METHOD(setupWithInitializationParameters:(NSString * _Nullable)initializationParametersStr config:(NSString *)config scanMode:(NSString *)scanMode onResultCallback:(RCTResponseSenderBlock)onResult onErrorCallback:(RCTResponseSenderBlock)onError) {
73
- self.onResultCallback = onResult;
74
- self.onErrorCallback = onError;
75
- self.returnMethod = @"callback";
76
- self.config = config;
77
- [self initView:scanMode initializationParamsStr:initializationParametersStr];
77
+ RCT_EXPORT_METHOD(setViewConfigsPath:(NSString *)path) {
78
+ scanViewConfigPathString = path;
78
79
  }
79
80
 
80
81
  RCT_EXPORT_METHOD(setupAnylineSDK:(NSString *)licenseKey
@@ -88,226 +89,201 @@ RCT_EXPORT_METHOD(setupAnylineSDKWithCacheConfig:(NSString *)licenseKey
88
89
  resolver:(RCTPromiseResolveBlock)resolve
89
90
  rejecter:(RCTPromiseRejectBlock)reject) {
90
91
 
91
- _resolveBlock = resolve;
92
- _rejectBlock = reject;
92
+ self.wrapperSessionSdkInitializationResponsePromiseResolve = resolve;
93
+ self.wrapperSessionSdkInitializationResponsePromiseReject = reject;
93
94
  self.returnMethod = @"promise";
94
95
 
95
- ALCacheConfig *cacheConfig = enableOfflineCache ? [ALCacheConfig offlineLicenseCachingEnabled] : nil;
96
- NSError *error;
96
+ [self initSdkWithLicenseKey:licenseKey sdkAssetsFolder:nil enableOfflineCache:enableOfflineCache];
97
+ }
97
98
 
98
- if ([AnylineSDKPlugin isInitializedWithLicenseKey:licenseKey]) {
99
- [self returnSuccess:@"success"];
100
- return;
101
- }
99
+ RCT_EXPORT_METHOD(isInitialized:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
100
+ ALWrapperSessionSDKInitializationResponse *currentSdkInitializationResponse = [ALWrapperSessionProvider getCurrentSdkInitializationResponse];
101
+ BOOL isInitialized = (currentSdkInitializationResponse.initialized != 0);
102
+ resolve(@(isInitialized));
103
+ }
102
104
 
103
- license = licenseKey;
105
+ RCT_EXPORT_METHOD(licenseKeyExpiryDate:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
106
+ ALWrapperSessionSDKInitializationResponse *currentSdkInitializationResponse = [ALWrapperSessionProvider getCurrentSdkInitializationResponse];
107
+ if (currentSdkInitializationResponse.initialized != 0) {
108
+ ALWrapperSessionSDKInitializationResponseInitialized *sdkInitializationResponseInitialized = currentSdkInitializationResponse.succeedInfo;
109
+ if (sdkInitializationResponseInitialized) {
110
+ resolve(sdkInitializationResponseInitialized.expiryDate);
111
+ return;
112
+ }
113
+ }
114
+ // not `reject`, as this will require the method to be used in a try-catch
115
+ resolve(nil);
116
+ return;
117
+ }
104
118
 
105
- BOOL success = [AnylineSDK setupWithLicenseKey:licenseKey cacheConfig:cacheConfig wrapperConfig:wrapperConfig error:&error];
119
+ // Deprecated
120
+ RCT_EXPORT_METHOD(setupScanViewWithConfigJson:(NSString *)config scanMode:(NSString *)scanMode onResultCallback:(RCTResponseSenderBlock)onResult onErrorCallback:(RCTResponseSenderBlock)onError) {
121
+ [self setupWithInitializationParameters:nil config:config scanMode:scanMode onResultCallback:onResult onErrorCallback:onError];
122
+ }
106
123
 
107
- NSString *errorString = nil;
108
- NSDictionary *successObj = nil;
124
+ RCT_EXPORT_METHOD(setup:(NSString *)config scanMode:(NSString *)scanMode onResultCallback:(RCTResponseSenderBlock)onResult onErrorCallback:(RCTResponseSenderBlock)onError) {
125
+ [self setupWithInitializationParameters:nil config:config scanMode:scanMode onResultCallback:onResult onErrorCallback:onError];
126
+ }
109
127
 
110
- if (!success) {
111
- NSLog(@"error: %@", error.localizedDescription);
112
- errorString = @"Unable to initialize the Anyline SDK. Please check your license key.";
113
- [self returnError:[NSError errorWithDomain:@"ALReactDomain" code:100 userInfo:@{NSLocalizedDescriptionKey: errorString}]];
114
- return;
115
- }
128
+ RCT_EXPORT_METHOD(setupWithInitializationParameters:(NSString * _Nullable)initializationParametersStr config:(NSString *)config scanMode:(NSString *)scanMode onResultCallback:(RCTResponseSenderBlock)onResult onErrorCallback:(RCTResponseSenderBlock)onError) {
129
+ self.scanResponseResultCallback = onResult;
130
+ self.scanResponseErrorCallback = onError;
131
+ self.returnMethod = @"callback";
116
132
 
117
- successObj = @{ @"success": @(true) };
118
- [self returnSuccess:@"success"];
133
+ [self requestScanStartWithScanViewConfigContent:config
134
+ scanViewInitializationParametersString:initializationParametersStr
135
+ scanViewConfigPath:scanViewConfigPathString
136
+ scanCallbackConfigString:nil];
119
137
  }
120
138
 
121
139
  RCT_EXPORT_METHOD(setupPromise:(NSString *)config scanMode:(NSString *)scanMode resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
122
140
  [self setupPromiseWithInitializationParameters:nil config:config scanMode:scanMode resolver:resolve rejecter:reject];
123
141
  }
124
142
 
125
- RCT_EXPORT_METHOD(setupPromiseWithInitializationParameters:(NSString * _Nullable)initializationParametersStr config:(NSString *)configStr scanMode:(NSString *)scanMode resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
126
- _resolveBlock = resolve;
127
- _rejectBlock = reject;
128
- self.returnMethod = @"promise";
129
- self.config = configStr;
130
- self.initializationParamsStr = initializationParametersStr;
131
- [self initView:scanMode initializationParamsStr:self.initializationParamsStr];
132
- }
133
-
134
- RCT_EXPORT_METHOD(getSDKVersion:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
135
- resolve(AnylineSDK.versionNumber);
143
+ RCT_EXPORT_METHOD(setupPromiseWithInitializationParameters:(NSString * _Nullable)initializationParametersStr
144
+ config:(NSString *)configStr
145
+ scanMode:(NSString *)scanMode
146
+ resolver:(RCTPromiseResolveBlock)resolve
147
+ rejecter:(RCTPromiseRejectBlock)reject) {
148
+ [self setupPromiseWithInitializationParametersAndScanCallbackConfig:initializationParametersStr
149
+ config:configStr
150
+ scanMode:scanMode
151
+ scanCallbackConfigString:nil
152
+ resolver:resolve
153
+ rejecter:reject];
136
154
  }
137
155
 
138
- RCT_EXPORT_METHOD(setPluginVersion:(NSString *)pluginVersion) {
139
- wrapperConfig = [ALWrapperConfig reactNative:pluginVersion];
156
+ RCT_EXPORT_METHOD(setupPromiseWithScanCallbackConfig:(NSString *)configStr
157
+ scanMode:(NSString *)scanMode
158
+ scanCallbackConfigString:(NSString *)scanCallbackConfigString
159
+ resolver:(RCTPromiseResolveBlock)resolve
160
+ rejecter:(RCTPromiseRejectBlock)reject) {
161
+ [self setupPromiseWithInitializationParametersAndScanCallbackConfig:nil
162
+ config:configStr
163
+ scanMode:scanMode
164
+ scanCallbackConfigString:scanCallbackConfigString
165
+ resolver:resolve
166
+ rejecter:reject];
140
167
  }
141
168
 
142
- RCT_EXPORT_METHOD(licenseKeyExpiryDate:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
143
- BOOL isInitialized = [[ALLicenseUtil sharedInstance] isLicenseValid];
144
- if (!isInitialized) {
145
- // not `reject`, as this will require the method to be used in a try-catch
146
- resolve(nil);
147
- return;
148
- }
149
- resolve([AnylineSDK licenseExpirationDate]);
169
+ RCT_EXPORT_METHOD(setupPromiseWithInitializationParametersAndScanCallbackConfig:(NSString * _Nullable)initializationParametersStr
170
+ config:(NSString *)configStr
171
+ scanMode:(NSString *)scanMode
172
+ scanCallbackConfigString:(NSString * _Nullable)scanCallbackConfigString
173
+ resolver:(RCTPromiseResolveBlock)resolve
174
+ rejecter:(RCTPromiseRejectBlock)reject) {
175
+ self.wrapperSessionScanResponsePromiseResolve = resolve;
176
+ self.wrapperSessionScanResponsePromiseReject = reject;
177
+ self.returnMethod = @"promise";
178
+ [self requestScanStartWithScanViewConfigContent:configStr
179
+ scanViewInitializationParametersString:initializationParametersStr
180
+ scanViewConfigPath:scanViewConfigPathString
181
+ scanCallbackConfigString:scanCallbackConfigString];
150
182
  }
151
183
 
152
- RCT_EXPORT_METHOD(isInitialized:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
153
- BOOL isInitialized = [AnylineSDK isInitialized];
154
- resolve(@(isInitialized));
184
+ RCT_EXPORT_METHOD(tryStopScan:(NSString * _Nullable)scanStopRequestParams) {
185
+ [ALWrapperSessionProvider requestScanStopWithScanStopRequestParamsString:scanStopRequestParams];
155
186
  }
156
187
 
157
188
  RCT_EXPORT_METHOD(reportCorrectedResult:(NSString *)blobKey
158
189
  correctedResult:(NSString *)correctedResult
159
190
  onResultCallback:(RCTResponseSenderBlock)onResult
160
191
  onErrorCallback:(RCTResponseSenderBlock)onError) {
192
+ self.reportCorrectedResultResponseCallback = onResult;
193
+ self.reportCorrectedResultErrorCallback = onError;
161
194
 
162
- NSError *error = nil;
163
-
164
- NSString *response = [ALScanResult reportCorrectedResultFromBlobKey:blobKey
165
- correctedResult:correctedResult
166
- apiKey:nil // apiKey should be nil
167
- error:&error];
168
- if (response) {
169
- NSError *jsonError = nil;
170
- NSData *jsonData = [response dataUsingEncoding:NSUTF8StringEncoding];
171
- NSDictionary *correctedResultJson = [NSJSONSerialization JSONObjectWithData:jsonData
172
- options:0
173
- error:&jsonError];
174
- if (jsonError) {
175
- onError(@[jsonError.localizedDescription]);
176
- return;
177
- }
178
-
179
- NSNumber *correctedResultCode = [correctedResultJson objectForKey:@"code"];
180
- NSString *correctedResultMessage = [correctedResultJson objectForKey:@"message"];
181
-
182
- if ([correctedResultCode intValue] == 200) {
183
- NSString *correctedResultInternalMessage = @"";
184
- if (correctedResultMessage) {
185
- NSError *messageJsonError = nil;
186
- NSData *messageJsonData = [correctedResultMessage dataUsingEncoding:NSUTF8StringEncoding];
187
- NSDictionary *messageJson = [NSJSONSerialization JSONObjectWithData:messageJsonData
188
- options:0
189
- error:&messageJsonError];
190
- if (!messageJsonError) {
191
- correctedResultInternalMessage = [messageJson objectForKey:@"message"];
192
- }
193
- }
194
- onResult(@[correctedResultInternalMessage]);
195
- } else {
196
- onError(@[correctedResultMessage]);
197
- }
198
- } else {
199
- onError(@[error.localizedDescription]);
200
- }
195
+ [self requestUCRReportWithBlobKey:blobKey correctedResult:correctedResult];
201
196
  }
202
197
 
203
198
 
204
199
  RCT_EXPORT_METHOD(exportCachedEvents:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
205
- _resolveBlock = resolve;
206
- _rejectBlock = reject;
207
- self.returnMethod = @"promise";
200
+ self.wrapperSessionExportCachedEventsPromiseResolve = resolve;
201
+ self.wrapperSessionExportCachedEventsPromiseReject = reject;
202
+ [self exportCachedEvents];
203
+ }
208
204
 
209
- NSError *error;
210
- NSString *exportPath = [AnylineSDK exportCachedEvents:&error];
211
205
 
212
- if (!exportPath) {
213
- NSString *errorString = @"Event cache is empty.";
214
- [self returnError:[NSError errorWithDomain:@"ALReactDomain" code:100 userInfo:@{NSLocalizedDescriptionKey: errorString}]];
215
- } else {
216
- [self returnSuccess:exportPath];
217
- }
206
+ - (NSArray<NSString *> *)supportedEvents {
207
+ return supportedRTCEventsArray;
218
208
  }
219
209
 
210
+ - (void)sendEvent:(NSString *)eventName
211
+ params:(id _Nullable) params {
220
212
 
221
- - (void)initView:(NSString *)scanMode initializationParamsStr:(NSString * _Nullable)initializationParamsStr {
222
- NSData *data = [self.config dataUsingEncoding:NSUTF8StringEncoding];
223
- if (!data) {
224
- [NSException raise:@"Config could not be loaded from disk" format:@"Config could not be loaded from disk"];
213
+ if (![supportedRTCEventsArray containsObject:eventName]) {
214
+ [supportedRTCEventsArray addObject:eventName];
225
215
  }
226
216
 
227
- NSError *error = nil;
228
- id dictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
217
+ [self sendEventWithName:eventName body:params];
218
+ }
229
219
 
230
- if (error) {
231
- [NSException raise:@"Config could not be parsed to JSON" format:@"Config could not be parsed to JSON: %@", error.localizedDescription];
220
+ -(NSString *)bundleRootPath {
221
+ NSString *rootPath = [[NSBundle mainBundle] bundlePath];
222
+ return rootPath;
223
+ }
224
+
225
+ -(NSString *)bundlePathFromScanViewConfigPath:(NSString * _Nullable)scanViewConfigPath {
226
+ //get root folder (ends with ...Runner.app)
227
+ NSString *absoluteScanViewConfigPath = [self bundleRootPath];
228
+
229
+ if (scanViewConfigPath) {
230
+ //append scanViewConfigPath
231
+ absoluteScanViewConfigPath = [absoluteScanViewConfigPath stringByAppendingPathComponent:scanViewConfigPath];
232
232
  }
233
- NSDictionary *optionsDictionary = [dictionary objectForKey:@"options"];
234
- self.jsonConfigDictionary = dictionary;
235
-
236
- BOOL nativeBarcodeScanning = [[optionsDictionary objectForKey:@"nativeBarcodeEnabled"] boolValue];
237
- self.nativeBarcodeScanning = nativeBarcodeScanning ? nativeBarcodeScanning : NO;
238
-
239
- self.jsonUIConf = [[ALJSONUIConfiguration alloc] initWithDictionary:optionsDictionary];
240
- self.ocrConfigDict = [dictionary objectForKey:@"ocr"];
241
-
242
- dispatch_async(dispatch_get_main_queue(), ^{
243
- [[UIApplication sharedApplication] keyWindow].rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
244
-
245
- if ([[scanMode uppercaseString] isEqualToString:[@"scan" uppercaseString]]) {
246
- ALPluginScanViewController *pluginScanViewController =
247
- [[ALPluginScanViewController alloc] initWithLicensekey:license
248
- configuration:dictionary
249
- uiConfiguration:self.jsonUIConf
250
- initializationParamsStr:initializationParamsStr
251
- finished:^(NSDictionary * _Nullable callbackObj, NSError * _Nullable error) {
252
- [self returnCallback:callbackObj andError:error];
253
- }];
254
-
255
- if (pluginScanViewController != nil){
256
- [pluginScanViewController setModalPresentationStyle: UIModalPresentationFullScreen];
257
- [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:pluginScanViewController animated:YES completion:nil];
258
- }
259
- } else {
260
- ALPluginScanViewController *pluginScanViewController =
261
- [[ALPluginScanViewController alloc] initWithLicensekey:license
262
- configuration:dictionary
263
- uiConfiguration:self.jsonUIConf
264
- initializationParamsStr:initializationParamsStr
265
- finished:^(NSDictionary * _Nullable callbackObj, NSError * _Nullable error) {
266
- [self returnCallback:callbackObj andError:error];
267
- }];
268
-
269
- if (pluginScanViewController != nil){
270
- [pluginScanViewController setModalPresentationStyle: UIModalPresentationFullScreen];
271
- [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:pluginScanViewController animated:YES completion:nil];
272
- }
273
- }
274
- });
233
+ return absoluteScanViewConfigPath;
234
+ }
275
235
 
236
+ - (void)setupWrapperSessionWithPluginVersion:(NSString *)pluginVersion {
237
+ // Setup wrapper session with this view controller as delegate
238
+ ALWrapperConfig *wrapperConfig = [ALWrapperConfig reactNative:pluginVersion];
239
+ [ALWrapperSessionProvider setupWrapperSessionWithWrapperInfo:wrapperConfig
240
+ wrapperSessionClient:self];
276
241
  }
277
242
 
278
- #pragma mark - ALPluginScanViewControllerDelegate
243
+ - (void)initSdkWithLicenseKey:(NSString *)sdkLicenseKey
244
+ sdkAssetsFolder: (NSString *)sdkAssetsFolder
245
+ enableOfflineCache: (BOOL)enableOfflineCache {
246
+ NSDictionary *wrapperSessionSdkInitializationRequestJson = [ALLegacyPluginHelper
247
+ sdkInitializationRequestJsonWithLicenseKey:sdkLicenseKey
248
+ enableOfflineCache:enableOfflineCache
249
+ assetPathPrefix:sdkAssetsFolder];
279
250
 
280
- - (void)pluginScanViewController:(nonnull ALPluginScanViewController *)pluginScanViewController didScan:(nonnull id)scanResult continueScanning:(BOOL)continueScanning {
281
- NSString *resultJson = @"";
251
+ [ALWrapperSessionProvider
252
+ requestSdkInitializationWithInitializationRequestParamsString:[wrapperSessionSdkInitializationRequestJson asJSONString]];
253
+ }
282
254
 
255
+ - (void)requestScanStartWithScanViewConfigContent:(NSString *)scanViewConfigContent
256
+ scanViewInitializationParametersString:(NSString * _Nullable)scanViewInitializationParametersString
257
+ scanViewConfigPath:(NSString * _Nullable)scanViewConfigPath
258
+ scanCallbackConfigString:(NSString * _Nullable)scanCallbackConfigString {
283
259
  NSError *error;
284
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject: scanResult
285
- options:0
286
- error:&error];
287
-
288
- if (! jsonData) {
289
- NSLog(@"bv_jsonStringWithPrettyPrint: error: %@", error.localizedDescription);
260
+ BOOL shouldReturnImages = true;
261
+
262
+ ALWrapperSessionScanStartRequest *wrapperSessionScanStartRequest = [ALLegacyPluginHelper
263
+ scanStartRequestWithScanViewConfigContentString:scanViewConfigContent
264
+ scanViewInitializationParametersString:scanViewInitializationParametersString
265
+ scanViewConfigPath:[self bundlePathFromScanViewConfigPath:scanViewConfigPath]
266
+ scanResultCallbackConfigString:scanCallbackConfigString
267
+ shouldReturnImages:shouldReturnImages
268
+ error:&error];
269
+ if (error) {
270
+ [self returnError:error];
290
271
  } else {
291
- resultJson = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
272
+ NSDictionary *wrapperSessionScanStartRequestDict = [wrapperSessionScanStartRequest toJSONDictionary];
273
+ [ALWrapperSessionProvider requestScanStartWithScanStartRequestParamsString:[wrapperSessionScanStartRequestDict asJSONString]];
292
274
  }
293
- [self returnSuccess:resultJson];
294
275
  }
295
276
 
296
- - (void)pluginScanViewController:(nonnull ALPluginScanViewController *)pluginScanViewController didStopScanning:(nonnull id)sender {
297
- [self returnError: [NSError errorWithDomain:@"ALReactDomain" code:100 userInfo:@{NSLocalizedDescriptionKey: @"Canceled"}]];
298
- }
277
+ - (void)requestUCRReportWithBlobKey:(NSString *)blobKey
278
+ correctedResult:(NSString *)correctedResult {
299
279
 
300
- - (void)pluginScanViewController:(ALPluginScanViewController *)pluginScanViewController didStopScanning:(id)sender error:(NSError *)error {
301
- [self returnError:error];
280
+ ALWrapperSessionUCRReportRequest *wrapperSessionSdkInitializationRequest = [ALLegacyPluginHelper ucrReportRequestWithBlobKey:blobKey
281
+ correctedResult:correctedResult];
282
+ [ALWrapperSessionProvider requestUCRReport:wrapperSessionSdkInitializationRequest];
302
283
  }
303
284
 
304
- - (BOOL)scanModeIndex:(NSString *)scanMode{
305
-
306
- NSArray *possibleScanModes = @[@"DOCUMENT", @"MRZ", @"BARCODE", @"LICENSE_PLATE", @"LICENSE_PLATE_US", @"ANYLINE_OCR", @"TIRE", @"ANALOG_METER", @"DIGITAL_METER", @"AUTO_ANALOG_DIGITAL_METER",
307
- @"DIAL_METER", @"SERIAL_NUMBER", @"HEAT_METER_4", @"HEAT_METER_5", @"HEAT_METER_6", @"DOT_MATRIX_METER"];
308
-
309
- return [possibleScanModes containsObject: [scanMode uppercaseString]];
310
-
285
+ -(void)exportCachedEvents {
286
+ [ALWrapperSessionProvider requestExportCachedEvents];
311
287
  }
312
288
 
313
289
  - (void)returnCallback:(id _Nullable)callbackObj andError:(NSError * _Nullable)error {
@@ -329,17 +305,108 @@ RCT_EXPORT_METHOD(exportCachedEvents:(RCTPromiseResolveBlock)resolve rejecter:(R
329
305
 
330
306
  - (void)returnSuccess:(NSString *)result {
331
307
  if ([self.returnMethod isEqualToString:@"callback"]) {
332
- self.onResultCallback(@[result]);
308
+ self.scanResponseResultCallback(@[result]);
333
309
  } else if ([self.returnMethod isEqualToString:@"promise"]) {
334
- _resolveBlock(result);
310
+ if (self.wrapperSessionScanResponsePromiseResolve) {
311
+ self.wrapperSessionScanResponsePromiseResolve(result);
312
+ }
313
+ self.wrapperSessionScanResponsePromiseResolve = nil;
335
314
  }
336
315
  }
337
316
 
338
317
  - (void)returnError:(NSError *)error {
339
318
  if ([self.returnMethod isEqualToString:@"callback"]) {
340
- self.onErrorCallback(@[error]);
319
+ self.scanResponseErrorCallback(@[error]);
341
320
  } else if ([self.returnMethod isEqualToString:@"promise"]) {
342
- _rejectBlock(@"ANYLINE_ERROR", error.localizedDescription, error);
321
+ if (self.wrapperSessionScanResponsePromiseReject) {
322
+ self.wrapperSessionScanResponsePromiseReject(@"ANYLINE_ERROR", error.localizedDescription, error);
323
+ }
324
+ self.wrapperSessionScanResponsePromiseReject = nil;
325
+ }
326
+ }
327
+
328
+ #pragma mark - ALWrapperSessionClientDelegate
329
+
330
+ - (nullable UIViewController *)getTopViewController {
331
+ UIViewController *topViewController = RCTPresentedViewController();
332
+ if (!topViewController) {
333
+ topViewController = [[UIApplication sharedApplication] keyWindow].rootViewController;
334
+ return topViewController;
335
+ }
336
+ return nil;
337
+ }
338
+
339
+ - (void)onSdkInitializationResponse:(nonnull ALWrapperSessionSDKInitializationResponse *)initializationResponse {
340
+ if (initializationResponse.initialized) {
341
+ self.wrapperSessionSdkInitializationResponsePromiseResolve(@"success");
342
+ } else {
343
+ self.wrapperSessionSdkInitializationResponsePromiseReject(@"ANYLINE_ERROR", [[initializationResponse toJSONDictionary] asJSONString], nil);
344
+ }
345
+ }
346
+
347
+ - (void)onScanResults:(nonnull ALWrapperSessionScanResultsResponse *)scanResultsResponse {
348
+ ALWrapperSessionScanResultConfig *scanResultConfig = scanResultsResponse.scanResultConfig;
349
+ NSArray<ALExportedScanResult *> *exportedScanResultsArray = (NSArray<ALExportedScanResult *> *) scanResultsResponse.exportedScanResults;
350
+ ALWrapperSessionScanResultExtraInfo *scanResultExtraInfo = scanResultsResponse.scanResultExtraInfo;
351
+
352
+ NSError *error;
353
+ NSString *resultsWithImagePathString = [ALLegacyPluginHelper scanResultsWithImagePathFromExportedScanResults:exportedScanResultsArray
354
+ viewPluginType:scanResultExtraInfo.viewPluginType
355
+ error:&error];
356
+
357
+ if (scanResultConfig.callbackConfig && scanResultConfig.callbackConfig.onResultEventName) {
358
+ [self sendEvent:scanResultConfig.callbackConfig.onResultEventName params:resultsWithImagePathString];
359
+ } else {
360
+ [self returnSuccess:resultsWithImagePathString];
361
+ }
362
+ }
363
+
364
+ - (void)onScanResponse:(nonnull ALWrapperSessionScanResponse *)scanResponse {
365
+ if (scanResponse.status == ALWrapperSessionScanResponseStatus.scanSucceeded) {
366
+ ALWrapperSessionScanResultConfig *scanResultConfig = scanResponse.scanResultConfig;
367
+ if (scanResultConfig.callbackConfig && scanResultConfig.callbackConfig.onResultEventName) {
368
+ [self returnSuccess:@""];
369
+ }
370
+ } else if (scanResponse.status == ALWrapperSessionScanResponseStatus.scanFailed) {
371
+ [self returnError:[NSError errorWithDomain:@"ALReactDomain" code:100 userInfo:@{NSLocalizedDescriptionKey: scanResponse.failInfo.lastError}]];
372
+ } else if (scanResponse.status == ALWrapperSessionScanResponseStatus.scanAborted) {
373
+ [self returnError:[NSError errorWithDomain:@"ALReactDomain" code:100 userInfo:@{NSLocalizedDescriptionKey: @"Canceled"}]];
374
+ }
375
+ }
376
+
377
+ - (void)onUIElementClicked:(nonnull ALWrapperSessionScanResultConfig *)scanResultConfig
378
+ uiFeedbackElementConfig:(nonnull ALUIFeedbackElementConfig *)uiFeedbackElementConfig {
379
+ if (scanResultConfig.callbackConfig && scanResultConfig.callbackConfig.onUIElementClickedEventName) {
380
+ [self sendEvent:scanResultConfig.callbackConfig.onUIElementClickedEventName
381
+ params:uiFeedbackElementConfig];
382
+ }
383
+ }
384
+
385
+ - (void)onUCRReportResponse:(nonnull ALWrapperSessionUCRReportResponse *)ucrReportResponse {
386
+ if (ucrReportResponse.status == ALWrapperSessionUCRReportResponseStatus.ucrReportSucceeded) {
387
+ ALWrapperSessionUCRReportResponseSucceed *ucrReportSucceed = ucrReportResponse.succeedInfo;
388
+ if (self.reportCorrectedResultResponseCallback) {
389
+ self.reportCorrectedResultResponseCallback(@[ucrReportSucceed.message]);
390
+ }
391
+ } else {
392
+ ALWrapperSessionUCRReportResponseFail *ucrReportFail = ucrReportResponse.failInfo;
393
+ if (self.reportCorrectedResultErrorCallback) {
394
+ self.reportCorrectedResultErrorCallback(@[ucrReportFail.lastError]);
395
+ }
396
+ }
397
+ }
398
+
399
+ - (void)onExportCachedEventsResponse:(nonnull ALWrapperSessionExportCachedEventsResponse *)exportCachedEventsResponse {
400
+ if (exportCachedEventsResponse.status == ALWrapperSessionExportCachedEventsResponseStatus.exportSucceeded) {
401
+ ALWrapperSessionExportCachedEventsResponseSucceed *exportCachedEventsSucceed = exportCachedEventsResponse.succeedInfo;
402
+ if (self.wrapperSessionExportCachedEventsPromiseResolve) {
403
+ self.wrapperSessionExportCachedEventsPromiseResolve(@[exportCachedEventsSucceed.exportedFile]);
404
+ }
405
+ } else {
406
+ ALWrapperSessionExportCachedEventsResponseFail *exportCachedEventsFail = exportCachedEventsResponse.failInfo;
407
+ if (self.wrapperSessionExportCachedEventsPromiseReject) {
408
+ self.wrapperSessionExportCachedEventsPromiseReject(@"ANYLINE_ERROR", exportCachedEventsFail.lastError, nil);
409
+ }
343
410
  }
344
411
  }
345
412
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anyline-ocr-react-native-module",
3
- "version": "55.2.1",
3
+ "version": "55.6.0",
4
4
  "description": "A Plugin for connecting Anyline with React-Native",
5
5
  "keywords": [
6
6
  "reactnative",