@sodyo/react-native-sodyo-sdk 5.0.2 → 5.1.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.
package/ios/RNSodyoSdk.m CHANGED
@@ -35,6 +35,11 @@ RCT_EXPORT_METHOD(createCloseContentListener)
35
35
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendCloseContentEvent) name:@"SodyoNotificationCloseIAD" object:nil];
36
36
  }
37
37
 
38
+ // Issue #4 fix: remove notification observer on dealloc
39
+ - (void)dealloc {
40
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
41
+ }
42
+
38
43
  RCT_EXPORT_METHOD(start)
39
44
  {
40
45
  NSLog(@"start");
@@ -92,7 +97,7 @@ RCT_EXPORT_METHOD(setDynamicProfileValue:(NSString *) key value:(NSString *) val
92
97
  RCT_EXPORT_METHOD(performMarker:(NSString *) markerId customProperties:(NSDictionary *) customProperties)
93
98
  {
94
99
  NSLog(@"performMarker");
95
- UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
100
+ UIViewController *rootViewController = [self getRootViewController];
96
101
  [SodyoSDK setPresentingViewController:rootViewController];
97
102
  [SodyoSDK performMarker:markerId customProperties:customProperties];
98
103
  }
@@ -100,28 +105,27 @@ RCT_EXPORT_METHOD(performMarker:(NSString *) markerId customProperties:(NSDictio
100
105
  RCT_EXPORT_METHOD(startTroubleshoot)
101
106
  {
102
107
  NSLog(@"startTroubleshoot");
103
-
104
- [SodyoSDK startTroubleshoot:sodyoScanner];
108
+ UIViewController *scanner = [RNSodyoScanner getSodyoScanner];
109
+ [SodyoSDK startTroubleshoot:scanner];
105
110
  }
106
111
 
107
112
 
108
113
  RCT_EXPORT_METHOD(setTroubleshootMode)
109
114
  {
110
115
  NSLog(@"setTroubleshootMode");
111
- sodyoScanner = [RNSodyoScanner getSodyoScanner];
112
-
113
- [SodyoSDK setMode:sodyoScanner mode:SodyoModeTroubleshoot];
116
+ UIViewController *scanner = [RNSodyoScanner getSodyoScanner];
117
+ [SodyoSDK setMode:scanner mode:SodyoModeTroubleshoot];
114
118
  }
115
119
 
116
120
  RCT_EXPORT_METHOD(setNormalMode)
117
121
  {
118
122
  NSLog(@"setNormalMode");
119
- sodyoScanner = [RNSodyoScanner getSodyoScanner];
120
-
121
- [SodyoSDK setMode:sodyoScanner mode:SodyoModeNormal];
123
+ UIViewController *scanner = [RNSodyoScanner getSodyoScanner];
124
+ [SodyoSDK setMode:scanner mode:SodyoModeNormal];
122
125
  }
123
126
 
124
- RCT_EXPORT_METHOD(setSodyoLogoVisible:(BOOL *) isVisible)
127
+ // Issue #3 fix: BOOL instead of BOOL*
128
+ RCT_EXPORT_METHOD(setSodyoLogoVisible:(BOOL) isVisible)
125
129
  {
126
130
  NSLog(@"setSodyoLogoVisible");
127
131
  if (isVisible) {
@@ -131,12 +135,18 @@ RCT_EXPORT_METHOD(setSodyoLogoVisible:(BOOL *) isVisible)
131
135
  [SodyoSDK hideDefaultOverlay];
132
136
  }
133
137
 
138
+ // Issue #8 fix: guard against nil env value
134
139
  RCT_EXPORT_METHOD(setEnv:(NSString *) env)
135
140
  {
136
141
  NSLog(@"setEnv");
137
142
 
138
143
  NSDictionary *envs = @{ @"DEV": @"3", @"QA": @"1", @"PROD": @"0" };
139
- NSDictionary *params = @{ @"SodyoAdEnv" : envs[env], @"ScanQR": @"false" };
144
+ NSString *envValue = envs[env];
145
+ if (!envValue) {
146
+ NSLog(@"RNSodyoSdk: Unknown env '%@', defaulting to PROD", env);
147
+ envValue = @"0";
148
+ }
149
+ NSDictionary *params = @{ @"SodyoAdEnv": envValue, @"ScanQR": @"false" };
140
150
  [SodyoSDK setScannerParams:params];
141
151
  }
142
152
 
@@ -145,29 +155,30 @@ RCT_EXPORT_METHOD(setEnv:(NSString *) env)
145
155
  return @[@"EventSodyoError", @"EventMarkerDetectSuccess", @"EventMarkerDetectError", @"EventMarkerContent", @"EventCloseSodyoContent", @"ModeChangeCallback"];
146
156
  }
147
157
 
158
+ // Issue #2 fix: inverted null-check + use shared scanner accessor
148
159
  - (void) launchSodyoScanner {
149
160
  NSLog(@"launchSodyoScanner");
150
- sodyoScanner = [RNSodyoScanner getSodyoScanner];
161
+ UIViewController *scanner = [RNSodyoScanner getSodyoScanner];
151
162
 
152
-
153
- if (!sodyoScanner) {
154
- [RNSodyoScanner setSodyoScanner:sodyoScanner];
163
+ if (!scanner) {
164
+ NSLog(@"Sodyo scanner not initialized");
165
+ return;
155
166
  }
156
167
 
157
- if (sodyoScanner.isViewLoaded && sodyoScanner.view.window) {
168
+ if (scanner.isViewLoaded && scanner.view.window) {
158
169
  NSLog(@"Sodyo scanner already active");
159
170
  return;
160
171
  }
161
172
 
162
- UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
163
- self->sodyoScanner.modalPresentationStyle = UIModalPresentationFullScreen;
173
+ UIViewController *rootViewController = [self getRootViewController];
174
+ scanner.modalPresentationStyle = UIModalPresentationFullScreen;
164
175
  [SodyoSDK setPresentingViewController:rootViewController];
165
- [rootViewController presentViewController:self->sodyoScanner animated:YES completion:nil];
176
+ [rootViewController presentViewController:scanner animated:YES completion:nil];
166
177
  }
167
178
 
168
179
  - (void) closeScanner {
169
180
  NSLog(@"closeScanner");
170
- UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
181
+ UIViewController *rootViewController = [self getRootViewController];
171
182
  [rootViewController dismissViewControllerAnimated:YES completion:nil];
172
183
  }
173
184
 
@@ -187,40 +198,71 @@ RCT_EXPORT_METHOD(setEnv:(NSString *) env)
187
198
  }
188
199
  }
189
200
 
201
+ // Issue #11 fix: UIScene-compatible root view controller access
202
+ - (UIViewController *)getRootViewController {
203
+ UIWindow *keyWindow = nil;
204
+ if (@available(iOS 13.0, *)) {
205
+ for (UIWindowScene *scene in [UIApplication sharedApplication].connectedScenes) {
206
+ if (scene.activationState == UISceneActivationStateForegroundActive) {
207
+ for (UIWindow *window in scene.windows) {
208
+ if (window.isKeyWindow) {
209
+ keyWindow = window;
210
+ break;
211
+ }
212
+ }
213
+ if (keyWindow) break;
214
+ }
215
+ }
216
+ }
217
+ if (!keyWindow) {
218
+ keyWindow = [UIApplication sharedApplication].delegate.window;
219
+ }
220
+ return keyWindow.rootViewController;
221
+ }
222
+
190
223
  #pragma mark - SodyoSDKDelegate
224
+ // Issue #5 fix: nil both callbacks after either fires
191
225
  - (void) onSodyoAppLoadSuccess:(NSInteger)AppID {
192
226
  NSLog(@"onSodyoAppLoadSuccess");
193
227
 
194
228
  if (self.successStartCallback != nil) {
195
229
  self.successStartCallback(@[[NSNull null]]);
196
- self.successStartCallback = nil;
197
230
  }
231
+ self.successStartCallback = nil;
232
+ self.errorStartCallback = nil;
198
233
  }
199
234
 
235
+ // Issue #6 fix: serialize NSError to string
200
236
  - (void) onSodyoAppLoadFailed:(NSInteger)AppID error:(NSError *)error {
201
237
  NSLog(@"Failed loading Sodyo: %@", error);
202
238
  if (self.errorStartCallback != nil) {
203
- self.errorStartCallback(@[@{@"error": error}]);
204
- self.errorStartCallback = nil;
239
+ NSString *message = error.localizedDescription ?: @"Unknown error";
240
+ self.errorStartCallback(@[@{@"error": message}]);
205
241
  }
242
+ self.successStartCallback = nil;
243
+ self.errorStartCallback = nil;
206
244
  }
207
245
 
246
+ // Issue #7 fix: guard against nil error description
208
247
  - (void) sodyoError:(NSError *)error {
209
248
  dispatch_async(dispatch_get_main_queue(), ^{
210
- NSLog(@"sodyoError: %@", error.userInfo[@"NSLocalizedDescription"]);
211
- NSArray* params = @[@"sodyoError", error.userInfo[@"NSLocalizedDescription"]];
212
- [self sendEventWithName:@"EventSodyoError" body:@{@"error": params[1]}];
249
+ NSString *desc = error.localizedDescription ?: @"Unknown error";
250
+ NSLog(@"sodyoError: %@", desc);
251
+ [self sendEventWithName:@"EventSodyoError" body:@{@"error": desc}];
213
252
  });
214
253
  }
215
254
 
255
+ // Issue #9 fix: guard against nil marker data
216
256
  - (void) SodyoMarkerDetectedWithData:(NSDictionary*)Data {
217
257
  NSLog(@"SodyoMarkerDetectedWithData: %@", Data[@"sodyoMarkerData"]);
218
- [self sendEventWithName:@"EventMarkerDetectSuccess" body:@{@"data": Data[@"sodyoMarkerData"]}];
258
+ id markerData = Data[@"sodyoMarkerData"] ?: [NSNull null];
259
+ [self sendEventWithName:@"EventMarkerDetectSuccess" body:@{@"data": markerData}];
219
260
  }
220
261
 
221
262
  - (void) SodyoMarkerContent:(NSString *)markerId Data:(NSDictionary *)Data {
222
- NSLog(@"SodyoMarkerDetectedWithData: %@", Data);
223
- [self sendEventWithName:@"EventMarkerContent" body:@{@"markerId": markerId, @"data": Data}];
263
+ NSLog(@"SodyoMarkerContent: %@", Data);
264
+ id data = Data ?: @{};
265
+ [self sendEventWithName:@"EventMarkerContent" body:@{@"markerId": markerId ?: @"", @"data": data}];
224
266
  }
225
267
 
226
268
 
@@ -232,4 +274,4 @@ RCT_EXPORT_METHOD(setEnv:(NSString *) env)
232
274
  [self sendEventWithName:@"ModeChangeCallback" body:@{@"oldMode": fromConverted, @"newMode": toConverted}];
233
275
  }
234
276
 
235
- @end
277
+ @end
@@ -16,64 +16,87 @@
16
16
  #import "RNSodyoSdkView.h"
17
17
  #import "RNSodyoScanner.h"
18
18
 
19
- @interface RNSodyoSdkManager : RCTViewManager {
20
- }
19
+ @interface RNSodyoSdkManager : RCTViewManager
21
20
  @end
22
21
 
23
22
  @implementation RNSodyoSdkManager
24
23
 
25
24
  RCT_EXPORT_MODULE(RNSodyoSdkView)
26
25
 
26
+ // Issue #11 fix: UIScene-compatible root view controller access
27
+ - (UIViewController *)getRootViewController {
28
+ UIWindow *keyWindow = nil;
29
+ if (@available(iOS 13.0, *)) {
30
+ for (UIWindowScene *scene in [UIApplication sharedApplication].connectedScenes) {
31
+ if (scene.activationState == UISceneActivationStateForegroundActive) {
32
+ for (UIWindow *window in scene.windows) {
33
+ if (window.isKeyWindow) {
34
+ keyWindow = window;
35
+ break;
36
+ }
37
+ }
38
+ if (keyWindow) break;
39
+ }
40
+ }
41
+ }
42
+ if (!keyWindow) {
43
+ keyWindow = [UIApplication sharedApplication].delegate.window;
44
+ }
45
+ return keyWindow.rootViewController;
46
+ }
47
+
27
48
  RCT_CUSTOM_VIEW_PROPERTY(isEnabled, BOOL, UIView)
28
49
  {
29
50
  NSLog(@"RNSodyoSdkManager set isEnabled");
30
51
 
31
- sodyoScanner = [RNSodyoScanner getSodyoScanner];
52
+ UIViewController *scanner = [RNSodyoScanner getSodyoScanner];
32
53
 
33
- if (!sodyoScanner) {
54
+ if (!scanner) {
34
55
  return;
35
56
  }
36
57
 
37
58
  if ([RCTConvert BOOL:json]) {
38
- [SodyoSDK startScanning:sodyoScanner];
59
+ [SodyoSDK startScanning:scanner];
39
60
  return;
40
61
  }
41
62
 
42
- [SodyoSDK stopScanning:sodyoScanner];
63
+ [SodyoSDK stopScanning:scanner];
43
64
  }
44
65
 
66
+ // Issue #13 fix: add false branch for troubleshooting toggle
45
67
  RCT_CUSTOM_VIEW_PROPERTY(isTroubleShootingEnabled, BOOL, UIView)
46
68
  {
47
69
  NSLog(@"RNSodyoSdkManager set isTroubleShootingEnabled");
48
70
 
49
- sodyoScanner = [RNSodyoScanner getSodyoScanner];
71
+ UIViewController *scanner = [RNSodyoScanner getSodyoScanner];
50
72
 
51
- if (!sodyoScanner) {
73
+ if (!scanner) {
52
74
  return;
53
75
  }
54
76
 
55
77
  if ([RCTConvert BOOL:json]) {
56
- [SodyoSDK startTroubleshoot:sodyoScanner];
78
+ [SodyoSDK startTroubleshoot:scanner];
57
79
  return;
58
80
  }
81
+
82
+ [SodyoSDK setMode:scanner mode:SodyoModeNormal];
59
83
  }
60
84
 
61
85
  - (UIView *)view
62
86
  {
63
- UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
87
+ UIViewController *rootViewController = [self getRootViewController];
64
88
 
65
- sodyoScanner = [SodyoSDK initSodyoScanner];
89
+ UIViewController *scanner = [SodyoSDK initSodyoScanner];
66
90
 
67
- [RNSodyoScanner setSodyoScanner:sodyoScanner];
68
- [rootViewController addChildViewController:sodyoScanner];
91
+ [RNSodyoScanner setSodyoScanner:scanner];
92
+ [rootViewController addChildViewController:scanner];
69
93
 
70
- RNSodyoSdkView *view = [[RNSodyoSdkView alloc] initWithView:sodyoScanner.view];
94
+ RNSodyoSdkView *view = [[RNSodyoSdkView alloc] initWithView:scanner.view scanner:scanner];
71
95
 
72
96
  [SodyoSDK setPresentingViewController:rootViewController];
73
- [sodyoScanner didMoveToParentViewController:rootViewController];
97
+ [scanner didMoveToParentViewController:rootViewController];
74
98
 
75
99
  return view;
76
100
  }
77
101
 
78
- @end
79
-
102
+ @end
@@ -1,5 +1,7 @@
1
1
  #import <UIKit/UIKit.h>
2
2
 
3
3
  @interface RNSodyoSdkView : UIView
4
- - (instancetype)initWithView:(UIView *)view;
5
- @end
4
+ @property (nonatomic, strong) UIView *scannerView;
5
+ @property (nonatomic, weak) UIViewController *scannerViewController;
6
+ - (instancetype)initWithView:(UIView *)view scanner:(UIViewController *)scanner;
7
+ @end
@@ -2,27 +2,51 @@
2
2
 
3
3
  @implementation RNSodyoSdkView
4
4
 
5
- - (instancetype)initWithView:(UIView*) view {
5
+ - (instancetype)initWithView:(UIView *)view scanner:(UIViewController *)scanner {
6
6
  NSLog(@"RNSodyoSdkView init");
7
7
  self = [super init];
8
8
 
9
- if ( self ) {
10
- [self setUp:view];
9
+ if (self) {
10
+ _scannerView = view;
11
+ _scannerViewController = scanner;
12
+ [self addSubview:view];
11
13
  }
12
14
 
13
15
  return self;
14
16
  }
15
17
 
16
- - (void)setUp:(UIView*) view {
17
- NSLog(@"RNSodyoSdkView setup");
18
- [self addSubview:view];
18
+ - (void)willMoveToSuperview:(UIView *)newSuperview {
19
+ // Temporarily detach scanner view before Fabric re-parents us
20
+ if (_scannerView && _scannerView.superview == self) {
21
+ [_scannerView removeFromSuperview];
22
+ }
23
+ [super willMoveToSuperview:newSuperview];
24
+ }
25
+
26
+ - (void)didMoveToSuperview {
27
+ [super didMoveToSuperview];
28
+ // Reattach scanner view after re-parenting is complete
29
+ if (_scannerView && self.superview && _scannerView.superview != self) {
30
+ [self addSubview:_scannerView];
31
+ _scannerView.frame = self.bounds;
32
+ }
19
33
  }
20
34
 
21
- - (void) layoutSubviews {
22
- [super layoutSubviews];
23
- for(UIView* view in self.subviews) {
24
- [view setFrame:self.bounds];
25
- }
35
+ - (void)layoutSubviews {
36
+ [super layoutSubviews];
37
+ for (UIView *view in self.subviews) {
38
+ [view setFrame:self.bounds];
39
+ }
40
+ }
41
+
42
+ // Issue #12 fix: remove child view controller on cleanup
43
+ - (void)removeFromSuperview {
44
+ if (_scannerViewController) {
45
+ [_scannerViewController willMoveToParentViewController:nil];
46
+ [_scannerViewController removeFromParentViewController];
47
+ _scannerViewController = nil;
48
+ }
49
+ [super removeFromSuperview];
26
50
  }
27
51
 
28
- @end
52
+ @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sodyo/react-native-sodyo-sdk",
3
- "version": "5.0.2",
3
+ "version": "5.1.0",
4
4
  "description": "RNSodyoSdk",
5
5
  "main": "sodyosdk.js",
6
6
  "typings": "./sodyosdk.d.ts",