react-native-insider 8.1.0 → 9.0.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 (48) hide show
  1. package/README.md +89 -660
  2. package/RNInsider.podspec +33 -12
  3. package/android/build.gradle +16 -2
  4. package/android/src/main/java/com/useinsider/react/RNInsiderAppFrameViewManager.java +253 -0
  5. package/android/src/main/java/com/useinsider/react/RNInsiderModule.java +238 -174
  6. package/android/src/main/java/com/useinsider/react/RNInsiderPackage.java +5 -1
  7. package/android/src/main/java/com/useinsider/react/RNUtils.java +111 -0
  8. package/babel.config.js +4 -1
  9. package/index.d.ts +196 -161
  10. package/index.js +60 -11
  11. package/ios/RNInsider/RNInsider.m +245 -341
  12. package/ios/RNInsider/RNInsiderAppFrameView.h +33 -0
  13. package/ios/RNInsider/RNInsiderAppFrameView.mm +315 -0
  14. package/ios/RNInsider/RNNotificationHandler.h +4 -1
  15. package/ios/RNInsider/RNNotificationHandler.m +16 -18
  16. package/ios/RNInsider/RNUtils.h +2 -0
  17. package/ios/RNInsider/RNUtils.m +79 -0
  18. package/package.json +43 -12
  19. package/src/EventHandler.js +17 -0
  20. package/src/InsiderAppFrame.d.ts +45 -0
  21. package/src/InsiderAppFrame.js +265 -0
  22. package/src/InsiderAppFrameLogic.d.ts +35 -0
  23. package/src/InsiderAppFrameLogic.js +192 -0
  24. package/src/InsiderAppFrameStatus.d.ts +22 -0
  25. package/src/InsiderAppFrameStatus.js +35 -0
  26. package/src/InsiderAppFramesError.d.ts +25 -0
  27. package/src/InsiderAppFramesError.js +77 -0
  28. package/src/InsiderEvent.js +1 -0
  29. package/src/InsiderEvents.d.ts +93 -0
  30. package/src/InsiderEvents.js +124 -0
  31. package/src/InsiderIdentifier.js +1 -1
  32. package/src/InsiderUser.d.ts +3 -2
  33. package/src/InsiderUser.js +27 -0
  34. package/src/Util.js +2 -1
  35. package/src/specs/InsiderAppFrameNativeComponent.ts +54 -0
  36. package/.orbit-output/config/MASTER.md +0 -129
  37. package/.orbit-output/config/architecture/API_DOCS.md +0 -342
  38. package/.orbit-output/config/architecture/ARCHITECTURE.md +0 -209
  39. package/.orbit-output/config/architecture/CODE-CATALOG.md +0 -172
  40. package/.orbit-output/config/architecture/project.yaml +0 -138
  41. package/.orbit-output/config/automation/AUTOMATION-SETUP.md +0 -50
  42. package/.orbit-output/config/enforcement/ENFORCEMENT-RULES.md +0 -41
  43. package/.orbit-output/config/enforcement/validate.sh +0 -49
  44. package/.orbit-output/skills/custom/academy-doc-generator.md +0 -598
  45. package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
  46. package/android/src/test/java/com/useinsider/react/RNInsiderModuleTest.java +0 -169
  47. package/docs/app-cards/app-cards_new.md +0 -569
  48. package/ios/RNInsiderTests/RNInsiderTriggerPushProcessTests.m +0 -91
@@ -18,57 +18,124 @@
18
18
  #import <InsiderHybrid/InsiderHybridMethods.h>
19
19
  #import <InsiderMobile/InsiderCallbackTypeEnum.h>
20
20
 
21
+ #pragma mark - Insider event listener
22
+
23
+ /**
24
+ * Dedicated observer for the SDK's recorded-event stream.
25
+ *
26
+ * iOS holds event observers WEAKLY (Android holds them strongly), so whatever object
27
+ * implements InsiderEventListener must be kept alive by us. RNInsider instances are
28
+ * created/destroyed by React Native and are not a safe owner, so this small class is
29
+ * retained by the file-static `insiderEventListener` below for as long as the JS side
30
+ * has at least one subscriber.
31
+ */
32
+ @interface RNInsiderEventListener : NSObject <InsiderEventListener>
33
+ @end
34
+
35
+ @implementation RNInsiderEventListener
36
+
37
+ - (void)onEventRecorded:(NSString *)name
38
+ parameters:(NSDictionary<NSString *, id> *)parameters
39
+ timestamp:(NSTimeInterval)timestamp {
40
+ @try {
41
+ if (name == nil) return;
42
+
43
+ // `parameters` is a defensive copy owned by the SDK — read only, never mutate.
44
+ //
45
+ // It MUST go through the converter rather than being passed straight through: RN's
46
+ // `convertIdToFollyDynamic` only understands NSNumber/NSString/NSArray/NSDictionary/
47
+ // NSNull, and turns anything else (NSDate in particular) into a NULL dynamic — the
48
+ // value would reach JS as `null`. See RNUtils.convertParametersForBridge:.
49
+ //
50
+ // `timestamp` is forwarded in WHOLE SECONDS, matching the native SDK. JS must
51
+ // do `new Date(timestamp * 1000)`. Note this differs deliberately from Date values
52
+ // nested inside `parameters`, which are normalized to epoch MILLIS for Android parity.
53
+ NSDictionary *payload = @{
54
+ @"name": name,
55
+ @"parameters": [RNUtils convertParametersForBridge:parameters],
56
+ @"timestamp": @(timestamp)
57
+ };
58
+
59
+ RNNotificationHandler *handler = [[RNNotificationHandler alloc] init];
60
+
61
+ // THREADING (verified against React Native 0.83 sources — do not re-litigate):
62
+ // this runs on the SDK's internal listener thread, and that is fine. No manual
63
+ // dispatch hop is needed, because RN marshals to the JS thread itself:
64
+ // RCTEventEmitter.sendEventWithName:body: (React/Modules/RCTEventEmitter.m:66)
65
+ // -> RCTCallableJSModules.invokeModule: (React/Base/RCTCallableJSModules.m:43/49)
66
+ // -> bridge: RCTCxxBridge.enqueueJSCall (explicitly annotated "AnyThread")
67
+ // -> NativeToJsBridge.cpp:298 m_executorMessageQueueThread->runOnQueue
68
+ // -> CFRunLoopPerformBlock onto the dedicated JS thread (FIFO).
69
+ // bridgeless: ReactInstance.cpp:299 bufferedRuntimeExecutor_->execute
70
+ // -> RuntimeScheduler task queue, drained on the JS thread.
71
+ // Adding our own queue here would buy nothing and would only add a second hop.
72
+ // Ordering is preserved on the bridge path, so sequential emits from this one SDK
73
+ // thread stay in order and a purchase cannot overtake a product_detail_page_view.
74
+ [handler sendDataToJS:INSIDER_EVENT_RECORDED data:payload];
75
+ } @catch (NSException *e) {
76
+ [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
77
+ }
78
+ }
79
+
80
+ @end
81
+
82
+ /// Strong reference keeping the weakly-held observer alive. Non-nil while registered.
83
+ static RNInsiderEventListener *insiderEventListener;
84
+
21
85
  @implementation RNInsider
22
86
 
23
87
  - (dispatch_queue_t)methodQueue
24
88
  {
25
89
  return dispatch_get_main_queue();
26
90
  }
91
+
92
+ + (BOOL)requiresMainQueueSetup {
93
+ return NO;
94
+ }
95
+
27
96
  RCT_EXPORT_MODULE()
28
97
 
29
- RCT_EXPORT_METHOD(initWithLaunchOptions:(NSDictionary *)launchOptions partnerName:(NSString *)partnerName appGroup:(NSString *)appGroup sdkVersion:(NSString *)sdkVersion) {
30
- @try {
31
- [Insider registerInsiderCallbackWithSelector:@selector(emitEvent:) sender:self];
32
- [Insider setHybridSDKVersion:sdkVersion];
98
+ - (NSString *)resolveAppIdentifier:(NSString *)app {
99
+ return app.length > 0 ? app : nil;
100
+ }
101
+
102
+ RCT_EXPORT_METHOD(initWithLaunchOptions:(NSDictionary *)launchOptions partnerName:(NSString *)partnerName appGroup:(NSString *)appGroup sdkVersion:(NSString *)sdkVersion appIdentifier:(NSString *)appIdentifier) {
103
+ [Insider registerInsiderCallbackWithSelector:@selector(emitEvent:) sender:self];
104
+ [Insider setHybridSDKVersion:sdkVersion];
105
+ NSString *app = [self resolveAppIdentifier:appIdentifier];
106
+ if (app) {
107
+ [Insider initWithLaunchOptions:nil partnerName:partnerName appGroup:appGroup appIdentifier:app];
108
+ } else {
33
109
  [Insider initWithLaunchOptions:nil partnerName:partnerName appGroup:appGroup];
34
- } @catch (NSException *e){
35
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
36
110
  }
37
111
  }
38
112
 
39
- RCT_EXPORT_METHOD(initWithCustomEndpoint:(NSDictionary *)launchOptions partnerName:(NSString *)partnerName appGroup:(NSString *)appGroup customEndpoint:(NSString *)endpoint sdkVersion:(NSString *)sdkVersion) {
40
- @try {
41
- [Insider registerInsiderCallbackWithSelector:@selector(emitEvent:) sender:self];
42
- [Insider setHybridSDKVersion:sdkVersion];
113
+ RCT_EXPORT_METHOD(initWithCustomEndpoint:(NSDictionary *)launchOptions partnerName:(NSString *)partnerName appGroup:(NSString *)appGroup customEndpoint:(NSString *)endpoint sdkVersion:(NSString *)sdkVersion appIdentifier:(NSString *)appIdentifier) {
114
+ [Insider registerInsiderCallbackWithSelector:@selector(emitEvent:) sender:self];
115
+ [Insider setHybridSDKVersion:sdkVersion];
116
+ NSString *app = [self resolveAppIdentifier:appIdentifier];
117
+ if (app) {
118
+ [Insider initWithLaunchOptions:nil partnerName:partnerName appGroup:appGroup customEndpoint:endpoint appIdentifier:app];
119
+ } else {
43
120
  [Insider initWithLaunchOptions:nil partnerName:partnerName appGroup:appGroup customEndpoint:endpoint];
44
- } @catch (NSException *e) {
45
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
46
121
  }
47
122
  }
48
123
 
49
124
  RCT_EXPORT_METHOD(reinitWithPartnerName:(NSString *)partnerName) {
50
- @try {
51
- [Insider reinitWithPartnerName:partnerName];
52
- } @catch (NSException *e){
53
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
54
- }
125
+ [Insider reinitWithPartnerName:partnerName];
55
126
  }
56
127
 
57
128
  RCT_EXPORT_METHOD(tagEvent:(NSString *)eventName withParameters:(NSArray *)parameters) {
58
129
  @try {
59
130
  [[RNUtils parseEventFromEventName:eventName andParameters:parameters] build];
60
- } @catch (NSException *e){
131
+ } @catch (NSException *e) {
61
132
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
62
133
  }
63
134
  }
64
135
 
65
136
  // Insider User
66
137
  RCT_EXPORT_METHOD(setGender:(int)gender) {
67
- @try {
68
- [InsiderHybrid setGender:gender];
69
- } @catch (NSException *e) {
70
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
71
- }
138
+ [InsiderHybrid setGender:gender];
72
139
  }
73
140
 
74
141
  RCT_EXPORT_METHOD(setBirthday:(NSString *)birthday) {
@@ -83,91 +150,47 @@ RCT_EXPORT_METHOD(setBirthday:(NSString *)birthday) {
83
150
  }
84
151
 
85
152
  RCT_EXPORT_METHOD(setName:(NSString *)value) {
86
- @try {
87
- [Insider getCurrentUser].setName(value);
88
- } @catch (NSException *e) {
89
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
90
- }
153
+ [Insider getCurrentUser].setName(value);
91
154
  }
92
155
 
93
156
  RCT_EXPORT_METHOD(setSurname:(NSString *)value) {
94
- @try {
95
- [Insider getCurrentUser].setSurname(value);
96
- } @catch (NSException *e) {
97
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
98
- }
157
+ [Insider getCurrentUser].setSurname(value);
99
158
  }
100
159
 
101
160
  RCT_EXPORT_METHOD(setAge:(int)value) {
102
- @try {
103
- [Insider getCurrentUser].setAge(value);
104
- } @catch (NSException *e) {
105
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
106
- }
161
+ [Insider getCurrentUser].setAge(value);
107
162
  }
108
163
 
109
164
  RCT_EXPORT_METHOD(setLanguage:(NSString *)value) {
110
- @try {
111
- [Insider getCurrentUser].setLanguage(value);
112
- } @catch (NSException *e) {
113
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
114
- }
165
+ [Insider getCurrentUser].setLanguage(value);
115
166
  }
116
167
 
117
168
  RCT_EXPORT_METHOD(setLocale:(NSString *)value) {
118
- @try {
119
- [Insider getCurrentUser].setLocale(value);
120
- } @catch (NSException *e) {
121
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
122
- }
169
+ [Insider getCurrentUser].setLocale(value);
123
170
  }
124
171
 
125
172
  RCT_EXPORT_METHOD(setFacebookID:(NSString *)value) {
126
- @try {
127
- [Insider getCurrentUser].setFacebookID(value);
128
- } @catch (NSException *e) {
129
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
130
- }
173
+ [Insider getCurrentUser].setFacebookID(value);
131
174
  }
132
175
 
133
176
  RCT_EXPORT_METHOD(setTwitterID:(NSString *)value) {
134
- @try {
135
- [Insider getCurrentUser].setTwitterID(value);
136
- } @catch (NSException *e) {
137
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
138
- }
177
+ [Insider getCurrentUser].setTwitterID(value);
139
178
  }
140
179
 
141
180
  RCT_EXPORT_METHOD(setEmailOptin:(BOOL)value) {
142
- @try {
143
- [Insider getCurrentUser].setEmailOptin(value);
144
- } @catch (NSException *e) {
145
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
146
- }
181
+ [Insider getCurrentUser].setEmailOptin(value);
147
182
  }
148
183
 
149
184
  RCT_EXPORT_METHOD(setEmail:(NSString *)value) {
150
- @try {
151
- [Insider getCurrentUser].setEmail(value);
152
- } @catch (NSException *e) {
153
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
154
- }
185
+ [Insider getCurrentUser].setEmail(value);
155
186
  }
156
187
 
157
188
  RCT_EXPORT_METHOD(setSMSOptin:(BOOL)value) {
158
- @try {
159
- [Insider getCurrentUser].setSMSOptin(value);
160
- } @catch (NSException *e) {
161
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
162
- }
189
+ [Insider getCurrentUser].setSMSOptin(value);
163
190
  }
164
191
 
165
192
  RCT_EXPORT_METHOD(setPhoneNumber:(NSString *)value) {
166
- @try {
167
- [Insider getCurrentUser].setPhoneNumber(value);
168
- } @catch (NSException *e) {
169
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
170
- }
193
+ [Insider getCurrentUser].setPhoneNumber(value);
171
194
  }
172
195
 
173
196
  RCT_EXPORT_METHOD(handleURL:(NSString *)value) {
@@ -185,24 +208,20 @@ RCT_EXPORT_METHOD(handleURL:(NSString *)value) {
185
208
  }
186
209
 
187
210
  RCT_EXPORT_METHOD(setPushOptin:(BOOL)value) {
188
- @try {
189
- [Insider getCurrentUser].setPushOptin(value);
190
- } @catch (NSException *e) {
191
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
192
- }
211
+ [Insider getCurrentUser].setPushOptin(value);
193
212
  }
194
213
 
195
214
  RCT_EXPORT_METHOD(setLocationOptin:(BOOL)value) {
196
- @try {
197
- [Insider getCurrentUser].setLocationOptin(value);
198
- } @catch (NSException *e) {
199
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
200
- }
215
+ [Insider getCurrentUser].setLocationOptin(value);
201
216
  }
202
217
 
203
218
  RCT_EXPORT_METHOD(setWhatsappOptin:(BOOL)value) {
219
+ [Insider getCurrentUser].setWhatsappOptin(value);
220
+ }
221
+
222
+ RCT_EXPORT_METHOD(setPromotionalOptin:(BOOL)value) {
204
223
  @try {
205
- [Insider getCurrentUser].setWhatsappOptin(value);
224
+ [Insider getCurrentUser].setPromotionalOptin(value);
206
225
  } @catch (NSException *e) {
207
226
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
208
227
  }
@@ -211,13 +230,14 @@ RCT_EXPORT_METHOD(setWhatsappOptin:(BOOL)value) {
211
230
  RCT_EXPORT_METHOD(login:(NSDictionary *)identifiers) {
212
231
  @try {
213
232
  if (!identifiers) return;
233
+
214
234
  InsiderIdentifiers *insiderIdentifiers = [[InsiderIdentifiers alloc] init];
215
- for (NSString *key in identifiers.allKeys){
216
- if([key isEqualToString:ADD_EMAIL]){
235
+ for (NSString *key in identifiers.allKeys) {
236
+ if ([key isEqualToString:ADD_EMAIL]) {
217
237
  insiderIdentifiers.addEmail([identifiers objectForKey:key]);
218
- } else if([key isEqualToString:ADD_PHONE_NUMBER]){
238
+ } else if ([key isEqualToString:ADD_PHONE_NUMBER]) {
219
239
  insiderIdentifiers.addPhoneNumber([identifiers objectForKey:key]);
220
- } else if([key isEqualToString:ADD_USER_ID]){
240
+ } else if ([key isEqualToString:ADD_USER_ID]) {
221
241
  insiderIdentifiers.addUserID([identifiers objectForKey:key]);
222
242
  } else {
223
243
  insiderIdentifiers.addCustomIdentifier(key, [identifiers objectForKey:key]);
@@ -230,34 +250,34 @@ RCT_EXPORT_METHOD(login:(NSDictionary *)identifiers) {
230
250
  }
231
251
  RCT_EXPORT_METHOD(loginWithReturningID:(NSDictionary *)identifiers insiderIDResult:(RCTResponseSenderBlock) insiderIDResult) {
232
252
  @try {
233
- if (!identifiers) return;
253
+ if (!identifiers) {
254
+ insiderIDResult(@[[NSNull null]]);
255
+ return;
256
+ }
257
+
234
258
  InsiderIdentifiers *insiderIdentifiers = [[InsiderIdentifiers alloc] init];
235
- for (NSString *key in identifiers.allKeys){
236
- if([key isEqualToString:ADD_EMAIL]){
259
+ for (NSString *key in identifiers.allKeys) {
260
+ if ([key isEqualToString:ADD_EMAIL]) {
237
261
  insiderIdentifiers.addEmail([identifiers objectForKey:key]);
238
- } else if([key isEqualToString:ADD_PHONE_NUMBER]){
262
+ } else if ([key isEqualToString:ADD_PHONE_NUMBER]) {
239
263
  insiderIdentifiers.addPhoneNumber([identifiers objectForKey:key]);
240
- } else if([key isEqualToString:ADD_USER_ID]){
264
+ } else if ([key isEqualToString:ADD_USER_ID]) {
241
265
  insiderIdentifiers.addUserID([identifiers objectForKey:key]);
242
266
  } else {
243
267
  insiderIdentifiers.addCustomIdentifier(key, [identifiers objectForKey:key]);
244
268
  }
245
269
  }
246
270
  [[Insider getCurrentUser] login:insiderIdentifiers insiderIDResult:^(NSString *insiderID) {
247
- NSArray *insiderIDToPass = [NSArray arrayWithObjects:insiderID, nil];
248
- insiderIDResult(insiderIDToPass);
271
+ insiderIDResult(@[insiderID ?: [NSNull null]]);
249
272
  }];
250
273
  } @catch (NSException *e) {
251
274
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
275
+ insiderIDResult(@[[NSNull null]]);
252
276
  }
253
277
  }
254
278
 
255
279
  RCT_EXPORT_METHOD(logout) {
256
- @try {
257
- [[Insider getCurrentUser] logout];
258
- } @catch (NSException *e) {
259
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
260
- }
280
+ [[Insider getCurrentUser] logout];
261
281
  }
262
282
 
263
283
  RCT_EXPORT_METHOD(logoutResettingInsiderID:(NSArray *)identifiersArray insiderIDResult:(RCTResponseSenderBlock)insiderIDResult) {
@@ -274,6 +294,10 @@ RCT_EXPORT_METHOD(logoutResettingInsiderID:(NSArray *)identifiersArray insiderID
274
294
  }
275
295
  } @catch (NSException *e) {
276
296
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
297
+
298
+ if (insiderIDResult != nil) {
299
+ insiderIDResult(@[[NSNull null]]);
300
+ }
277
301
  }
278
302
  }
279
303
 
@@ -302,35 +326,19 @@ RCT_EXPORT_METHOD(logoutResettingInsiderID:(NSArray *)identifiersArray insiderID
302
326
  }
303
327
 
304
328
  RCT_EXPORT_METHOD(setCustomAttributeWithString:(NSString *)key value:(NSString *)value) {
305
- @try {
306
- [Insider getCurrentUser].setCustomAttributeWithString(key, value);
307
- } @catch (NSException *e) {
308
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
309
- }
329
+ [Insider getCurrentUser].setCustomAttributeWithString(key, value);
310
330
  }
311
331
 
312
332
  RCT_EXPORT_METHOD(setCustomAttributeWithInt:(NSString *)key value:(int)value) {
313
- @try {
314
- [Insider getCurrentUser].setCustomAttributeWithInt(key, value);
315
- } @catch (NSException *e) {
316
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
317
- }
333
+ [Insider getCurrentUser].setCustomAttributeWithInt(key, value);
318
334
  }
319
335
 
320
336
  RCT_EXPORT_METHOD(setCustomAttributeWithDouble:(NSString *)key value:(double)value) {
321
- @try {
322
- [Insider getCurrentUser].setCustomAttributeWithDouble(key, value);
323
- } @catch (NSException *e) {
324
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
325
- }
337
+ [Insider getCurrentUser].setCustomAttributeWithDouble(key, value);
326
338
  }
327
339
 
328
340
  RCT_EXPORT_METHOD(setCustomAttributeWithBoolean:(NSString *)key value:(BOOL)value) {
329
- @try {
330
- [Insider getCurrentUser].setCustomAttributeWithBoolean(key, value);
331
- } @catch (NSException *e) {
332
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
333
- }
341
+ [Insider getCurrentUser].setCustomAttributeWithBoolean(key, value);
334
342
  }
335
343
 
336
344
  RCT_EXPORT_METHOD(setCustomAttributeWithDate:(NSString *)key value:(NSString *)value) {
@@ -345,35 +353,19 @@ RCT_EXPORT_METHOD(setCustomAttributeWithDate:(NSString *)key value:(NSString *)v
345
353
  }
346
354
 
347
355
  RCT_EXPORT_METHOD(setCustomAttributeWithArray:(NSString *)key value:(NSArray *)value) {
348
- @try {
349
- [Insider getCurrentUser].setCustomAttributeWithArray(key, value);
350
- } @catch (NSException *e) {
351
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
352
- }
356
+ [Insider getCurrentUser].setCustomAttributeWithArray(key, value);
353
357
  }
354
358
 
355
359
  RCT_EXPORT_METHOD(unsetCustomAttribute:(NSString *)key) {
356
- @try {
357
- [Insider getCurrentUser].unsetCustomAttribute(key);
358
- } @catch (NSException *e) {
359
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
360
- }
360
+ [Insider getCurrentUser].unsetCustomAttribute(key);
361
361
  }
362
362
 
363
363
  RCT_EXPORT_METHOD(setGDPRConsent:(BOOL)gdprConsent) {
364
- @try {
365
- [Insider setGDPRConsent:gdprConsent];
366
- } @catch (NSException *e){
367
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
368
- }
364
+ [Insider setGDPRConsent:gdprConsent];
369
365
  }
370
366
 
371
367
  RCT_EXPORT_METHOD(setMobileAppAccess:(BOOL)mobileAppAccess) {
372
- @try {
373
- [Insider setMobileAppAccess:mobileAppAccess];
374
- } @catch (NSException *e){
375
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
376
- }
368
+ [Insider setMobileAppAccess:mobileAppAccess];
377
369
  }
378
370
 
379
371
  RCT_EXPORT_METHOD(signUpConfirmation:(NSArray *)customParameters) {
@@ -385,7 +377,7 @@ RCT_EXPORT_METHOD(signUpConfirmation:(NSArray *)customParameters) {
385
377
  } else {
386
378
  [Insider signUpConfirmation];
387
379
  }
388
- } @catch (NSException *e){
380
+ } @catch (NSException *e) {
389
381
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
390
382
  }
391
383
  }
@@ -401,7 +393,7 @@ RCT_EXPORT_METHOD(itemPurchased:(NSString *)saleID requiredFields:(NSDictionary
401
393
  } else {
402
394
  [Insider itemPurchasedWithSaleID:saleID product:product];
403
395
  }
404
- } @catch (NSException *e){
396
+ } @catch (NSException *e) {
405
397
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
406
398
  }
407
399
  }
@@ -416,38 +408,30 @@ RCT_EXPORT_METHOD(itemAddedToCart:(NSDictionary *)requiredFields optionalFields:
416
408
  } else {
417
409
  [Insider itemAddedToCartWithProduct:product];
418
410
  }
419
- } @catch (NSException *e){
411
+ } @catch (NSException *e) {
420
412
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
421
413
  }
422
414
  }
423
415
 
424
416
  RCT_EXPORT_METHOD(itemRemovedFromCart:(NSString *)productID saleID:(NSString *)saleID customParameters:(NSArray *)customParameters) {
425
- @try {
426
- NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
417
+ NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
427
418
 
428
- if (saleID.length > 0) {
429
- [Insider itemRemovedFromCartWithProductID:productID saleID:saleID customParameters:mappedCustomParameters];
430
- } else if (mappedCustomParameters.count > 0) {
431
- [Insider itemRemovedFromCartWithProductID:productID customParameters:mappedCustomParameters];
432
- } else {
433
- [Insider itemRemovedFromCartWithProductID:productID];
434
- }
435
- } @catch (NSException *e){
436
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
419
+ if (saleID.length > 0) {
420
+ [Insider itemRemovedFromCartWithProductID:productID saleID:saleID customParameters:mappedCustomParameters];
421
+ } else if (mappedCustomParameters.count > 0) {
422
+ [Insider itemRemovedFromCartWithProductID:productID customParameters:mappedCustomParameters];
423
+ } else {
424
+ [Insider itemRemovedFromCartWithProductID:productID];
437
425
  }
438
426
  }
439
427
 
440
428
  RCT_EXPORT_METHOD(cartCleared:(NSArray *)customParameters) {
441
- @try {
442
- NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
429
+ NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
443
430
 
444
- if (mappedCustomParameters.count > 0) {
445
- [Insider cartClearedWithCustomParameters:mappedCustomParameters];
446
- } else {
447
- [Insider cartCleared];
448
- }
449
- } @catch (NSException *e){
450
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
431
+ if (mappedCustomParameters.count > 0) {
432
+ [Insider cartClearedWithCustomParameters:mappedCustomParameters];
433
+ } else {
434
+ [Insider cartCleared];
451
435
  }
452
436
  }
453
437
 
@@ -461,36 +445,28 @@ RCT_EXPORT_METHOD(itemAddedToWishlist:(NSDictionary *)requiredFields optionalFie
461
445
  } else {
462
446
  [Insider itemAddedToWishlistWithProduct:product];
463
447
  }
464
- } @catch (NSException *e){
448
+ } @catch (NSException *e) {
465
449
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
466
450
  }
467
451
  }
468
452
 
469
453
  RCT_EXPORT_METHOD(itemRemovedFromWishlist:(NSString *)productID customParameters:(NSArray *)customParameters) {
470
- @try {
471
- NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
454
+ NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
472
455
 
473
- if (mappedCustomParameters.count > 0) {
474
- [Insider itemRemovedFromWishlistWithProductID:productID customParameters:mappedCustomParameters];
475
- } else {
476
- [Insider itemRemovedFromWishlistWithProductID:productID];
477
- }
478
- } @catch (NSException *e){
479
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
456
+ if (mappedCustomParameters.count > 0) {
457
+ [Insider itemRemovedFromWishlistWithProductID:productID customParameters:mappedCustomParameters];
458
+ } else {
459
+ [Insider itemRemovedFromWishlistWithProductID:productID];
480
460
  }
481
461
  }
482
462
 
483
463
  RCT_EXPORT_METHOD(wishlistCleared:(NSArray *)customParameters) {
484
- @try {
485
- NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
464
+ NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
486
465
 
487
- if (mappedCustomParameters.count > 0) {
488
- [Insider wishlistClearedWithCustomParameters:mappedCustomParameters];
489
- } else {
490
- [Insider wishlistCleared];
491
- }
492
- } @catch (NSException *e){
493
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
466
+ if (mappedCustomParameters.count > 0) {
467
+ [Insider wishlistClearedWithCustomParameters:mappedCustomParameters];
468
+ } else {
469
+ [Insider wishlistCleared];
494
470
  }
495
471
  }
496
472
 
@@ -501,8 +477,9 @@ RCT_EXPORT_METHOD(getMessageCenterData:(NSInteger)limit startDate:(NSString *)st
501
477
  [InsiderHybrid getMessageCenterDataWithLimit:limit startDate:startDateEpoch endDate:endDateEpoch success:^(NSArray *messageCenterData) {
502
478
  callback(messageCenterData);
503
479
  }];
504
- } @catch (NSException *e){
480
+ } @catch (NSException *e) {
505
481
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
482
+ callback(@[@{@"data": @[]}]);
506
483
  }
507
484
  }
508
485
 
@@ -535,6 +512,7 @@ RCT_EXPORT_METHOD(getMessageCenterDataWithIdentifiers:(NSInteger)limit startDate
535
512
  }];
536
513
  } @catch (NSException *e) {
537
514
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
515
+ callback(@[@[]]);
538
516
  }
539
517
  }
540
518
 
@@ -545,6 +523,7 @@ RCT_EXPORT_METHOD(getSmartRecommendation:(int)recommendationID locale:(NSString
545
523
  }];
546
524
  } @catch (NSException *e) {
547
525
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
526
+ smartRecommendation(@[@{}]);
548
527
  }
549
528
  }
550
529
 
@@ -556,6 +535,7 @@ RCT_EXPORT_METHOD(getSmartRecommendationWithProduct:(NSDictionary *)requiredFiel
556
535
  }];
557
536
  } @catch (NSException *e) {
558
537
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
538
+ smartRecommendation(@[@{}]);
559
539
  }
560
540
  }
561
541
 
@@ -566,6 +546,7 @@ RCT_EXPORT_METHOD(getSmartRecommendationWithProductIDs:(NSArray *)productIDs rec
566
546
  }];
567
547
  } @catch (NSException *e) {
568
548
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
549
+ smartRecommendation(@[@{}]);
569
550
  }
570
551
  }
571
552
 
@@ -579,78 +560,54 @@ RCT_EXPORT_METHOD(clickSmartRecommendationProduct:(int)recommendationID required
579
560
  }
580
561
 
581
562
  RCT_EXPORT_METHOD(getContentStringWithName:(NSString *)variableName defaultValue:(NSString *)defaultValue dataType:(int)dataType callback:(RCTResponseSenderBlock)callback) {
582
- @try {
583
- callback([InsiderHybrid getContentStringWithName:variableName defaultString:defaultValue dataType:dataType]);
584
- } @catch (NSException *e){
585
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
586
- }
563
+ callback([InsiderHybrid getContentStringWithName:variableName defaultString:defaultValue dataType:dataType]);
587
564
  }
588
565
 
589
566
  RCT_EXPORT_METHOD(getContentBoolWithName:(NSString *)variableName defaultValue:(BOOL)defaultValue dataType:(int)dataType callback:(RCTResponseSenderBlock)callback) {
590
- @try {
591
- callback([InsiderHybrid getContentBoolWithName:variableName defaultBool:defaultValue dataType:dataType]);
592
- } @catch (NSException *e){
593
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
594
- }
567
+ callback([InsiderHybrid getContentBoolWithName:variableName defaultBool:defaultValue dataType:dataType]);
595
568
  }
596
569
 
597
570
  RCT_EXPORT_METHOD(getContentIntWithName:(NSString *)variableName defaultValue:(int)defaultValue dataType:(int)dataType callback:(RCTResponseSenderBlock)callback) {
598
- @try {
599
- callback([InsiderHybrid getContentIntWithName:variableName defaultInt:defaultValue dataType:dataType]);
600
- } @catch (NSException *e){
601
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
602
- }
571
+ callback([InsiderHybrid getContentIntWithName:variableName defaultInt:defaultValue dataType:dataType]);
603
572
  }
604
573
 
605
574
  RCT_EXPORT_METHOD(getContentStringWithoutCache:(NSString *)variableName defaultValue:(NSString *)defaultValue dataType:(int)dataType callback:(RCTResponseSenderBlock)callback) {
606
- @try {
607
- callback([InsiderHybrid getContentStringWithoutCache:variableName defaultString:defaultValue dataType:dataType]);
608
- } @catch (NSException *e){
609
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
610
- }
575
+ callback([InsiderHybrid getContentStringWithoutCache:variableName defaultString:defaultValue dataType:dataType]);
611
576
  }
612
577
 
613
578
  RCT_EXPORT_METHOD(getContentBoolWithoutCache:(NSString *)variableName defaultValue:(BOOL)defaultValue dataType:(int)dataType callback:(RCTResponseSenderBlock)callback) {
614
- @try {
615
- callback([InsiderHybrid getContentBoolWithoutCache:variableName defaultBool:defaultValue dataType:dataType]);
616
- } @catch (NSException *e){
617
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
618
- }
579
+ callback([InsiderHybrid getContentBoolWithoutCache:variableName defaultBool:defaultValue dataType:dataType]);
619
580
  }
620
581
 
621
582
  RCT_EXPORT_METHOD(getContentIntWithoutCache:(NSString *)variableName defaultValue:(int)defaultValue dataType:(int)dataType callback:(RCTResponseSenderBlock)callback) {
583
+ callback([InsiderHybrid getContentIntWithoutCache:variableName defaultInt:defaultValue dataType:dataType]);
584
+ }
585
+
586
+ RCT_EXPORT_METHOD(markContentOptimizerAsSeen:(NSString *)variableName) {
622
587
  @try {
623
- callback([InsiderHybrid getContentIntWithoutCache:variableName defaultInt:defaultValue dataType:dataType]);
588
+ [Insider markContentOptimizerAsSeen:variableName];
624
589
  } @catch (NSException *e){
625
590
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
626
591
  }
627
592
  }
628
593
 
629
594
  RCT_EXPORT_METHOD(visitHomePage:(NSArray *)customParameters) {
630
- @try {
631
- NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
595
+ NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
632
596
 
633
- if (mappedCustomParameters.count > 0) {
634
- [Insider visitHomepageWithCustomParameters:mappedCustomParameters];
635
- } else {
636
- [Insider visitHomepage];
637
- }
638
- } @catch (NSException *e) {
639
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
597
+ if (mappedCustomParameters.count > 0) {
598
+ [Insider visitHomepageWithCustomParameters:mappedCustomParameters];
599
+ } else {
600
+ [Insider visitHomepage];
640
601
  }
641
602
  }
642
603
 
643
604
  RCT_EXPORT_METHOD(visitListingPage:(NSArray *)taxonomy customParameters:(NSArray *)customParameters) {
644
- @try {
645
- NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
605
+ NSDictionary<NSString *, id> *mappedCustomParameters = [RNUtils parseCustomParameters:customParameters];
646
606
 
647
- if (mappedCustomParameters.count > 0) {
648
- [Insider visitListingPageWithTaxonomy:taxonomy customParameters:mappedCustomParameters];
649
- } else {
650
- [Insider visitListingPageWithTaxonomy:taxonomy];
651
- }
652
- } @catch (NSException *e) {
653
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
607
+ if (mappedCustomParameters.count > 0) {
608
+ [Insider visitListingPageWithTaxonomy:taxonomy customParameters:mappedCustomParameters];
609
+ } else {
610
+ [Insider visitListingPageWithTaxonomy:taxonomy];
654
611
  }
655
612
  }
656
613
 
@@ -718,19 +675,11 @@ RCT_EXPORT_METHOD(visitWishlistPage:(NSArray *)products customParameters:(NSArra
718
675
  }
719
676
 
720
677
  RCT_EXPORT_METHOD(startTrackingGeofence) {
721
- @try {
722
- [InsiderGeofence startTracking];
723
- } @catch (NSException *e){
724
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
725
- }
678
+ [InsiderGeofence startTracking];
726
679
  }
727
680
 
728
681
  RCT_EXPORT_METHOD(setAllowsBackgroundLocationUpdates:(BOOL)allowsBackgroundLocationUpdates) {
729
- @try {
730
- [InsiderGeofence setAllowsBackgroundLocationUpdates:allowsBackgroundLocationUpdates];
731
- } @catch (NSException *e) {
732
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
733
- }
682
+ [InsiderGeofence setAllowsBackgroundLocationUpdates:allowsBackgroundLocationUpdates];
734
683
  }
735
684
 
736
685
  RCT_EXPORT_METHOD(handleNotification:(NSDictionary *)notification) {
@@ -739,7 +688,7 @@ RCT_EXPORT_METHOD(handleNotification:(NSDictionary *)notification) {
739
688
  mutableNotification[@"aps"] = @"insider";
740
689
  [Insider handlePushLogWithUserInfo:mutableNotification];
741
690
  [Insider trackInteractiveLogWithUserInfo:mutableNotification];
742
- } @catch (NSException *e){
691
+ } @catch (NSException *e) {
743
692
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
744
693
  }
745
694
  }
@@ -749,100 +698,52 @@ RCT_EXPORT_METHOD(triggerPushProcessWithNotificationData:(NSDictionary *)notific
749
698
  }
750
699
 
751
700
  RCT_EXPORT_METHOD(enableIDFACollection:(BOOL)enableIDFACollection) {
752
- @try {
753
- [Insider enableIDFACollection:enableIDFACollection];
754
- } @catch (NSException *e){
755
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
756
- }
701
+ [Insider enableIDFACollection:enableIDFACollection];
757
702
  }
758
703
 
759
704
  RCT_EXPORT_METHOD(removeInapp) {
760
- @try {
761
- [Insider removeInapp];
762
- } @catch (NSException *e) {
763
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
764
- }
705
+ [Insider removeInapp];
765
706
  }
766
707
 
767
708
  RCT_EXPORT_METHOD(registerWithQuietPermission:(BOOL)enabled) {
768
- @try {
769
- [Insider registerWithQuietPermission:enabled];
770
- } @catch (NSException *e){
771
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
772
- }
709
+ [Insider registerWithQuietPermission:enabled];
773
710
  }
774
711
 
775
712
  RCT_EXPORT_METHOD(putErrorLog:(NSString *)errorString) {
776
- @try{
777
- NSException *exception = [NSException exceptionWithName:@"[JavaScript Error]" reason:errorString userInfo:nil];
778
- [Insider sendError:exception desc:@"RNInsider.m - JavaScript Error"];
779
- } @catch (NSException *e) {
780
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
781
- }
713
+ NSException *exception = [NSException exceptionWithName:@"[JavaScript Error]" reason:errorString userInfo:nil];
714
+ [Insider sendError:exception desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
782
715
  }
783
716
 
784
717
  RCT_EXPORT_METHOD(showNativeAppReview) {
785
- @try {
786
- [Insider showNativeAppReview];
787
- } @catch (NSException *e) {
788
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
789
- }
718
+ [Insider showNativeAppReview];
790
719
  }
791
720
 
792
721
  RCT_EXPORT_METHOD(enableLocationCollection:(BOOL)enabled) {
793
- @try {
794
- [Insider enableLocationCollection:enabled];
795
- } @catch (NSException *e){
796
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
797
- }
722
+ [Insider enableLocationCollection:enabled];
798
723
  }
799
724
 
800
725
  RCT_EXPORT_METHOD(enableIpCollection:(BOOL)enabled) {
801
- @try {
802
- [Insider enableIpCollection:enabled];
803
- } @catch (NSException *e){
804
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
805
- }
726
+ [Insider enableIpCollection:enabled];
806
727
  }
807
728
 
808
729
  RCT_EXPORT_METHOD(enableCarrierCollection:(BOOL)enabled) {
809
- @try {
810
- [Insider enableCarrierCollection:enabled];
811
- } @catch (NSException *e){
812
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
813
- }
730
+ [Insider enableCarrierCollection:enabled];
814
731
  }
815
732
 
816
733
  RCT_EXPORT_METHOD(setForegroundPushCallback) {
817
- @try {
818
- [Insider setForegroundPushCallback:@selector(foregroundPushCallback:) sender:self];
819
- } @catch (NSException *e){
820
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
821
- }
734
+ [Insider setForegroundPushCallback:@selector(foregroundPushCallback:) sender:self];
822
735
  }
823
736
 
824
737
  RCT_EXPORT_METHOD(setActiveForegroundPushView) {
825
- @try {
826
- [Insider setActiveForegroundPushView];
827
- } @catch (NSException *e){
828
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
829
- }
738
+ [Insider setActiveForegroundPushView];
830
739
  }
831
740
 
832
741
  RCT_EXPORT_METHOD(disableTemplates:(NSString *)value) {
833
- @try {
834
- [Insider disableTemplates];
835
- } @catch (NSException *e) {
836
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
837
- }
742
+ [Insider disableTemplates];
838
743
  }
839
744
 
840
745
  RCT_EXPORT_METHOD(reenableTemplates:(NSString *)value) {
841
- @try {
842
- [Insider reenableTemplates];
843
- } @catch (NSException *e) {
844
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
845
- }
746
+ [Insider reenableTemplates];
846
747
  }
847
748
 
848
749
  RCT_EXPORT_METHOD(getInsiderID:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
@@ -856,27 +757,42 @@ RCT_EXPORT_METHOD(getInsiderID:(RCTPromiseResolveBlock)resolve rejecter:(RCTProm
856
757
  }
857
758
 
858
759
  RCT_EXPORT_METHOD(registerInsiderIDListener) {
760
+ [Insider registerInsiderIDListenerWithSelector:@selector(insiderIDChangeListener:) sender:self];
761
+ }
762
+
763
+ RCT_EXPORT_METHOD(registerInsiderEventListener) {
859
764
  @try {
860
- [Insider registerInsiderIDListenerWithSelector:@selector(insiderIDChangeListener:) sender:self];
765
+ if (insiderEventListener != nil) return;
766
+
767
+ insiderEventListener = [[RNInsiderEventListener alloc] init];
768
+
769
+ [[Insider events] addObserver:insiderEventListener];
861
770
  } @catch (NSException *e) {
771
+ insiderEventListener = nil;
862
772
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
863
773
  }
864
774
  }
865
775
 
866
- RCT_EXPORT_METHOD(disableInAppMessages) {
776
+ RCT_EXPORT_METHOD(unregisterInsiderEventListener) {
867
777
  @try {
868
- [Insider disableInAppMessages];
869
- } @catch (NSException *e){
778
+ if (insiderEventListener == nil) return;
779
+
780
+ [[Insider events] removeObserver:insiderEventListener];
781
+
782
+ // Dropping our strong reference is what actually deallocates the observer,
783
+ // since the SDK only holds it weakly.
784
+ insiderEventListener = nil;
785
+ } @catch (NSException *e) {
870
786
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
871
787
  }
872
788
  }
873
789
 
790
+ RCT_EXPORT_METHOD(disableInAppMessages) {
791
+ [Insider disableInAppMessages];
792
+ }
793
+
874
794
  RCT_EXPORT_METHOD(enableInAppMessages) {
875
- @try {
876
- [Insider enableInAppMessages];
877
- } @catch (NSException *e){
878
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
879
- }
795
+ [Insider enableInAppMessages];
880
796
  }
881
797
 
882
798
  RCT_EXPORT_METHOD(getAppCardsCampaigns:(RCTResponseSenderBlock)callback) {
@@ -944,64 +860,52 @@ RCT_EXPORT_METHOD(deleteAppCards:(NSArray<NSString *> *)appCardIds callback:(RCT
944
860
  }
945
861
 
946
862
  RCT_EXPORT_METHOD(clickAppCardButton:(NSString *)appCardId data:(NSDictionary *)data) {
947
- @try {
948
- InsiderAppCardButtonModel *model = [[InsiderAppCardButtonModel alloc] initWithDictionary:data error:nil];
949
- if (model) {
950
- [model setAppCardId:appCardId];
951
- [model click];
952
- }
953
- } @catch (NSException *e) {
954
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
863
+ InsiderAppCardButtonModel *model = [[InsiderAppCardButtonModel alloc] initWithDictionary:data error:nil];
864
+ if (model) {
865
+ [model setAppCardId:appCardId];
866
+ [model click];
955
867
  }
956
868
  }
957
869
 
958
870
  RCT_EXPORT_METHOD(viewAppCard:(NSDictionary *)data) {
959
- @try {
960
- InsiderAppCardModel *model = [[InsiderAppCardModel alloc] initWithDictionary:data error:nil];
961
- if (model) {
962
- [model view];
963
- }
964
- } @catch (NSException *e) {
965
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
871
+ InsiderAppCardModel *model = [[InsiderAppCardModel alloc] initWithDictionary:data error:nil];
872
+ if (model) {
873
+ [model view];
966
874
  }
967
875
  }
968
876
 
969
877
  RCT_EXPORT_METHOD(clickAppCard:(NSDictionary *)data) {
970
- @try {
971
- InsiderAppCardModel *model = [[InsiderAppCardModel alloc] initWithDictionary:data error:nil];
972
- if (model) {
973
- [model click];
974
- }
975
- } @catch (NSException *e) {
976
- [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
878
+ InsiderAppCardModel *model = [[InsiderAppCardModel alloc] initWithDictionary:data error:nil];
879
+ if (model) {
880
+ [model click];
977
881
  }
978
882
  }
979
883
 
980
- -(void)insiderIDChangeListener:(NSString *) insiderID {
884
+ - (void)insiderIDChangeListener:(NSString *) insiderID {
981
885
  @try {
982
886
  if (insiderID == nil) return;
983
887
 
984
888
  RNNotificationHandler *handler = [[RNNotificationHandler alloc] init];
985
889
 
986
890
  [handler sendDataToJS:INSIDER_ID_LISTENER data:insiderID];
987
- } @catch (NSException *e){
891
+ } @catch (NSException *e) {
988
892
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
989
893
  }
990
894
  }
991
895
 
992
- -(void)foregroundPushCallback:(UNNotification *) notification {
896
+ - (void)foregroundPushCallback:(UNNotification *) notification {
993
897
  @try {
994
898
  if (notification == nil) return;
995
899
 
996
900
  RNNotificationHandler *handler = [[RNNotificationHandler alloc] init];
997
901
 
998
902
  [handler sendDataToJS:@"FOREGROUND_PUSH" data:notification.request.content.userInfo];
999
- } @catch (NSException *e){
903
+ } @catch (NSException *e) {
1000
904
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
1001
905
  }
1002
906
  }
1003
907
 
1004
- -(void)emitEvent:(NSDictionary *)eventData {
908
+ - (void)emitEvent:(NSDictionary *)eventData {
1005
909
  @try {
1006
910
  RNNotificationHandler *handler = [[RNNotificationHandler alloc] init];
1007
911
  if (!eventData || [eventData count] == 0)
@@ -1032,7 +936,7 @@ RCT_EXPORT_METHOD(clickAppCard:(NSDictionary *)data) {
1032
936
  default:
1033
937
  break;
1034
938
  }
1035
- } @catch (NSException *e){
939
+ } @catch (NSException *e) {
1036
940
  [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
1037
941
  }
1038
942
  }