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

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.
@@ -1,6 +1,6 @@
1
1
  require "json"
2
2
 
3
- package = JSON.parse(File.read(File.join(__dir__, "../", "package.json")))
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
4
 
5
5
  Pod::Spec.new do |s|
6
6
  s.name = "AnylineReact"
@@ -17,8 +17,8 @@ Pod::Spec.new do |s|
17
17
 
18
18
  s.source = { :git => "https://github.com/Anyline/anyline-ocr-react-native-module.git", :tag => "#{s.version}" }
19
19
 
20
- s.source_files = "*.{h,m}"
21
- s.dependency "Anyline", "55.0.3"
20
+ s.source_files = 'ios/**/*.{h,m,swift}'
21
+ s.dependency "Anyline", "55.2.1"
22
22
  s.dependency "React"
23
23
 
24
24
  end
File without changes
@@ -0,0 +1,2 @@
1
+ #Thu Jun 26 13:03:14 CEST 2025
2
+ gradle.version=7.6
File without changes
package/android/.project CHANGED
@@ -22,12 +22,12 @@
22
22
  </natures>
23
23
  <filteredResources>
24
24
  <filter>
25
- <id>1644311700731</id>
25
+ <id>1748580469394</id>
26
26
  <name></name>
27
27
  <type>30</type>
28
28
  <matcher>
29
29
  <id>org.eclipse.core.resources.regexFilterMatcher</id>
30
- <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
30
+ <arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
31
31
  </matcher>
32
32
  </filter>
33
33
  </filteredResources>
@@ -61,7 +61,7 @@ repositories {
61
61
 
62
62
  dependencies {
63
63
  implementation fileTree(dir: "libs", include: ["*.jar"])
64
- implementation 'io.anyline:anylinesdk:55.0.3'
64
+ implementation 'io.anyline:anylinesdk:55.2.1'
65
65
  implementation "com.facebook.react:react-native:+"
66
66
  implementation("com.google.android.material:material:1.9.0")
67
67
  implementation 'androidx.multidex:multidex:2.0.1'
@@ -29,7 +29,7 @@ import io.anyline2.legacy.products.AnylineUpdater;
29
29
  import io.anyline2.legacy.trainer.AssetContext;
30
30
  import io.anyline2.AnylineSdk;
31
31
  import io.anyline2.CacheConfig;
32
- import io.anyline2.CorrectedResultReporting;
32
+ import io.anyline2.ScanResult;
33
33
  import io.anyline2.core.LicenseException;
34
34
 
35
35
  class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultReporter.OnResultListener {
@@ -39,6 +39,15 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
39
39
  System.loadLibrary("anylineCore");
40
40
  }
41
41
 
42
+ // We're creating a static variable to retain the SDK instance in order to prevent crashes due to garbage collection cleaning up the SDK.
43
+ protected static final AnylineSdk anylineSdk = AnylineSdk.INSTANCE;
44
+ // We're creating a static variable to store the last license used to initialize the SDK
45
+ private static String license;
46
+
47
+ private static boolean isInitializedWithLicenseKey(String requestedLicense) {
48
+ return (license != null && AnylineSdk.isInitialized() && license.equals(requestedLicense));
49
+ }
50
+
42
51
  public static final String REACT_CLASS = "AnylineSDKPlugin";
43
52
  public static final String EXTRA_CONFIG_JSON = "EXTRA_CONFIG_JSON";
44
53
  public static final String EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS = "EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS";
@@ -53,7 +62,6 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
53
62
  private static final String E_ERROR = "E_ERROR";
54
63
  private JSONObject configObject;
55
64
  private ReactApplicationContext reactContext;
56
- private String license;
57
65
  private JSONObject options;
58
66
  private Callback onResultCallback;
59
67
  private Callback onErrorCallback;
@@ -94,7 +102,6 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
94
102
  try {
95
103
  promise.resolve(String.valueOf(AnylineSdk.getExpiryDate()));
96
104
  } catch (LicenseException e) {
97
- e.printStackTrace();
98
105
  promise.reject(E_ERROR, e.getMessage());
99
106
  }
100
107
  }
@@ -133,7 +140,6 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
133
140
  );
134
141
  }
135
142
  } catch (JSONException e) {
136
- e.printStackTrace();
137
143
  returnError(e.getMessage());
138
144
  }
139
145
  }
@@ -145,6 +151,11 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
145
151
 
146
152
  @ReactMethod
147
153
  public void setupAnylineSDKWithCacheConfig(String license, boolean enableOfflineCache, final Promise promise) {
154
+ if (isInitializedWithLicenseKey(license)) {
155
+ promise.resolve(true);
156
+ return;
157
+ }
158
+
148
159
  CacheConfig.Preset cacheConfig = CacheConfig.Preset.Default.INSTANCE;
149
160
  if (enableOfflineCache) {
150
161
  cacheConfig = CacheConfig.Preset.OfflineLicenseEventCachingEnabled.INSTANCE;
@@ -156,7 +167,6 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
156
167
  promise.resolve(true);
157
168
  }
158
169
  } catch (LicenseException e) {
159
- e.printStackTrace();
160
170
  if (promise != null) {
161
171
  promise.reject(E_ERROR, e.getMessage());
162
172
  }
@@ -170,14 +180,18 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
170
180
 
171
181
  @ReactMethod
172
182
  public void initSdkWithCacheConfig(String license, boolean enableOfflineCache) {
183
+ if (isInitializedWithLicenseKey(license)) {
184
+ return;
185
+ }
186
+
173
187
  CacheConfig.Preset cacheConfig = CacheConfig.Preset.Default.INSTANCE;
174
188
  if (enableOfflineCache) {
175
189
  cacheConfig = CacheConfig.Preset.OfflineLicenseEventCachingEnabled.INSTANCE;
176
190
  }
177
191
  try {
178
192
  AnylineSdk.init(license, reactContext, "", cacheConfig, wrapperConfig);
193
+ this.license = license;
179
194
  } catch (LicenseException e) {
180
- e.printStackTrace();
181
195
  returnError(e.getMessage());
182
196
  }
183
197
  }
@@ -204,22 +218,28 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
204
218
  }
205
219
 
206
220
  @ReactMethod
207
- public void reportCorrectedResult(String blobKey, String correctedResult, Callback onResponseCallback) {
208
- HashMap<String, String> hashMap = new HashMap<>();
209
- hashMap.put("result", correctedResult);
210
-
221
+ public void reportCorrectedResult(String blobKey, String correctedResult, Callback onResponseCallback, Callback onErrorCallback) {
211
222
  try {
212
- CorrectedResultReporting
213
- .Factory
214
- .getInstance()
215
- .reportCorrectedResult(
216
- blobKey,
217
- hashMap
218
- );
219
- onResponseCallback.invoke("Success");
223
+ String correctedResultReturn = ScanResult.reportCorrectedResultFromBlobKey(blobKey, correctedResult);
224
+ try {
225
+ JSONObject correctedResultJson = new JSONObject(correctedResultReturn);
226
+ int correctedResultCode = correctedResultJson.optInt("code", 0);
227
+ String correctedResultMessage = correctedResultJson.optString("message");
228
+ if (correctedResultCode == 200) {
229
+ String correctedResultInternalMessage = "";
230
+ if (correctedResultMessage != null) {
231
+ correctedResultInternalMessage = new JSONObject(correctedResultMessage).optString("message");
232
+ }
233
+ onResponseCallback.invoke(correctedResultInternalMessage);
234
+ } else {
235
+ onErrorCallback.invoke(correctedResultMessage);
236
+ }
237
+ } catch (JSONException e) {
238
+ onErrorCallback.invoke(e.getMessage());
239
+ }
220
240
  }
221
241
  catch (IllegalArgumentException e) {
222
- onResponseCallback.invoke("Error: " + e.getMessage());
242
+ onErrorCallback.invoke(e.getMessage());
223
243
  }
224
244
  }
225
245
 
@@ -307,10 +327,8 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
307
327
  returnError("No ViewPlugin in config. Please check your configuration.");
308
328
  }
309
329
  } catch (LicenseException e) {
310
- e.printStackTrace();
311
330
  returnError("LICENSE ERROR: " + e.getMessage());
312
331
  } catch (JSONException e) {
313
- e.printStackTrace();
314
332
  returnError("JSON ERROR: " + e.getMessage());
315
333
  }
316
334
  }
package/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import {NativeModules} from 'react-native';
2
- import AnylineOCR from 'anyline-ocr-react-native-module';
3
2
  import {version as pluginVersion} from './package.json';
4
3
 
5
4
  const Buffer = require('buffer/').Buffer;
6
5
 
7
- export default NativeModules.AnylineSDKPlugin;
6
+ const AnylineOCR = NativeModules.AnylineSDKPlugin;
7
+
8
+ export default AnylineOCR;
8
9
 
9
10
  /**
10
11
  * Decrypts the License and returns the date till it's valid
@@ -4,14 +4,16 @@
4
4
  #import "ALPluginScanViewController.h"
5
5
  #import "ALPluginHelper.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;
9
+ // We're creating a static variable to store the last license used to initialize the SDK
10
+ static NSString *license;
11
+
7
12
  ALWrapperConfig *wrapperConfig = nil;
8
13
 
9
14
  @interface AnylineSDKPlugin()
10
15
 
11
- @property (nonatomic, strong) ALViewPluginConfig *conf;
12
-
13
16
  @property (nonatomic, copy) NSString *callbackId;
14
- @property (nonatomic, copy) NSString *appKey;
15
17
  @property (nonatomic, assign) BOOL nativeBarcodeScanning;
16
18
  @property (nonatomic, strong) NSDictionary *jsonConfigDictionary;
17
19
  @property (nonatomic, strong) NSDictionary *ocrConfigDict;
@@ -21,7 +23,6 @@ ALWrapperConfig *wrapperConfig = nil;
21
23
  @property (nonatomic, strong) RCTResponseSenderBlock onErrorCallback;
22
24
 
23
25
  @property (nonatomic, copy) NSString *config;
24
- @property (nonatomic, copy) NSString *licenseKey;
25
26
 
26
27
  @property (nonatomic, copy) NSString *returnMethod;
27
28
 
@@ -35,6 +36,21 @@ ALWrapperConfig *wrapperConfig = nil;
35
36
  RCTPromiseRejectBlock _rejectBlock;
36
37
  }
37
38
 
39
+ + (BOOL)isInitializedWithLicenseKey:(NSString *)requestedLicense {
40
+ return (license && [AnylineSDK isInitialized] && [license isEqualToString:requestedLicense]);
41
+ }
42
+
43
+ - (instancetype)init {
44
+ self = [super init];
45
+ if (self) {
46
+ if (!anylineSDK) {
47
+ // Initialize the anylineSDK static variable
48
+ anylineSDK = [[AnylineSDK alloc] init];
49
+ }
50
+ }
51
+ return self;
52
+ }
53
+
38
54
  RCT_EXPORT_MODULE();
39
55
  - (UIView *)view {
40
56
  return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
@@ -75,10 +91,17 @@ RCT_EXPORT_METHOD(setupAnylineSDKWithCacheConfig:(NSString *)licenseKey
75
91
  _resolveBlock = resolve;
76
92
  _rejectBlock = reject;
77
93
  self.returnMethod = @"promise";
78
- self.licenseKey = licenseKey;
79
94
 
80
95
  ALCacheConfig *cacheConfig = enableOfflineCache ? [ALCacheConfig offlineLicenseCachingEnabled] : nil;
81
96
  NSError *error;
97
+
98
+ if ([AnylineSDKPlugin isInitializedWithLicenseKey:licenseKey]) {
99
+ [self returnSuccess:@"success"];
100
+ return;
101
+ }
102
+
103
+ license = licenseKey;
104
+
82
105
  BOOL success = [AnylineSDK setupWithLicenseKey:licenseKey cacheConfig:cacheConfig wrapperConfig:wrapperConfig error:&error];
83
106
 
84
107
  NSString *errorString = nil;
@@ -131,6 +154,53 @@ RCT_EXPORT_METHOD(isInitialized:(RCTPromiseResolveBlock)resolve rejecter:(RCTPro
131
154
  resolve(@(isInitialized));
132
155
  }
133
156
 
157
+ RCT_EXPORT_METHOD(reportCorrectedResult:(NSString *)blobKey
158
+ correctedResult:(NSString *)correctedResult
159
+ onResultCallback:(RCTResponseSenderBlock)onResult
160
+ onErrorCallback:(RCTResponseSenderBlock)onError) {
161
+
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
+ }
201
+ }
202
+
203
+
134
204
  RCT_EXPORT_METHOD(exportCachedEvents:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
135
205
  _resolveBlock = resolve;
136
206
  _rejectBlock = reject;
@@ -163,16 +233,10 @@ RCT_EXPORT_METHOD(exportCachedEvents:(RCTPromiseResolveBlock)resolve rejecter:(R
163
233
  NSDictionary *optionsDictionary = [dictionary objectForKey:@"options"];
164
234
  self.jsonConfigDictionary = dictionary;
165
235
 
166
- self.appKey = [dictionary objectForKey:@"license"];
167
- if (!self.appKey) {
168
- self.appKey = [dictionary objectForKey:@"licenseKey"];
169
- }
170
-
171
236
  BOOL nativeBarcodeScanning = [[optionsDictionary objectForKey:@"nativeBarcodeEnabled"] boolValue];
172
237
  self.nativeBarcodeScanning = nativeBarcodeScanning ? nativeBarcodeScanning : NO;
173
238
 
174
239
  self.jsonUIConf = [[ALJSONUIConfiguration alloc] initWithDictionary:optionsDictionary];
175
- self.conf = [[ALViewPluginConfig alloc] initWithJSONDictionary:optionsDictionary error:&error];
176
240
  self.ocrConfigDict = [dictionary objectForKey:@"ocr"];
177
241
 
178
242
  dispatch_async(dispatch_get_main_queue(), ^{
@@ -180,7 +244,7 @@ RCT_EXPORT_METHOD(exportCachedEvents:(RCTPromiseResolveBlock)resolve rejecter:(R
180
244
 
181
245
  if ([[scanMode uppercaseString] isEqualToString:[@"scan" uppercaseString]]) {
182
246
  ALPluginScanViewController *pluginScanViewController =
183
- [[ALPluginScanViewController alloc] initWithLicensekey:self.appKey
247
+ [[ALPluginScanViewController alloc] initWithLicensekey:license
184
248
  configuration:dictionary
185
249
  uiConfiguration:self.jsonUIConf
186
250
  initializationParamsStr:initializationParamsStr
@@ -194,7 +258,7 @@ RCT_EXPORT_METHOD(exportCachedEvents:(RCTPromiseResolveBlock)resolve rejecter:(R
194
258
  }
195
259
  } else {
196
260
  ALPluginScanViewController *pluginScanViewController =
197
- [[ALPluginScanViewController alloc] initWithLicensekey:self.appKey
261
+ [[ALPluginScanViewController alloc] initWithLicensekey:license
198
262
  configuration:dictionary
199
263
  uiConfiguration:self.jsonUIConf
200
264
  initializationParamsStr:initializationParamsStr
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anyline-ocr-react-native-module",
3
- "version": "55.0.3",
3
+ "version": "55.2.1",
4
4
  "description": "A Plugin for connecting Anyline with React-Native",
5
5
  "keywords": [
6
6
  "reactnative",
@@ -24,5 +24,15 @@
24
24
  "buffer": "^5.1.0"
25
25
  },
26
26
  "bundleDependencies": false,
27
- "deprecated": false
27
+ "deprecated": false,
28
+ "react-native": {
29
+ "ios": {
30
+ "podspecPath": "./AnylineReact.podspec"
31
+ },
32
+ "android": {
33
+ "sourceDir": "./android",
34
+ "packageImportPath": "import com.anyline.reactnative.AnylinePackage;",
35
+ "packageInstance": "new AnylinePackage()"
36
+ }
37
+ }
28
38
  }