reactnative-plugin-appice 1.7.14 → 1.7.16

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 (105) hide show
  1. package/README.md +37 -37
  2. package/android/README.md +14 -14
  3. package/android/build.gradle +153 -151
  4. package/android/gitignore +47 -47
  5. package/android/gradle/wrapper/gradle-wrapper.properties +5 -5
  6. package/android/gradlew +234 -234
  7. package/android/local.properties +8 -8
  8. package/android/src/main/AndroidManifest.xml +153 -153
  9. package/android/src/main/java/com/reactlibrary/AppICEUtils.java +241 -241
  10. package/android/src/main/java/com/reactlibrary/AppIceReactPluginModule.java +748 -748
  11. package/android/src/main/java/com/reactlibrary/AppIceReactPluginPackage.java +28 -28
  12. package/android/src/main/java/com/reactlibrary/CampaignCampsReceiver.java +56 -56
  13. package/android/src/main/java/com/reactlibrary/EnumConstants.java +256 -256
  14. package/android/src/main/java/com/reactlibrary/NotificationEventService.java +59 -59
  15. package/android/src/main/java/com/reactlibrary/StringConstants.java +9 -9
  16. package/example/App.js +292 -292
  17. package/example/Gemfile +6 -6
  18. package/example/__tests__/App-test.js +14 -14
  19. package/example/ancilliary.js +484 -474
  20. package/example/android/app/_BUCK +55 -55
  21. package/example/android/app/build.gradle +320 -320
  22. package/example/android/app/build_defs.bzl +19 -19
  23. package/example/android/app/proguard-rules.pro +10 -10
  24. package/example/android/app/src/debug/AndroidManifest.xml +13 -13
  25. package/example/android/app/src/debug/java/com/example/ReactNativeFlipper.java +73 -73
  26. package/example/android/app/src/main/AndroidManifest.xml +72 -72
  27. package/example/android/app/src/main/java/com/example/MainActivity.java +48 -48
  28. package/example/android/app/src/main/java/com/example/MainApplication.java +91 -91
  29. package/example/android/app/src/main/java/com/example/newarchitecture/MainApplicationReactNativeHost.java +116 -116
  30. package/example/android/app/src/main/java/com/example/newarchitecture/components/MainComponentsRegistry.java +36 -36
  31. package/example/android/app/src/main/java/com/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java +48 -48
  32. package/example/android/app/src/main/jni/Android.mk +48 -48
  33. package/example/android/app/src/main/jni/MainApplicationModuleProvider.cpp +24 -24
  34. package/example/android/app/src/main/jni/MainApplicationModuleProvider.h +16 -16
  35. package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp +45 -45
  36. package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h +38 -38
  37. package/example/android/app/src/main/jni/MainComponentsRegistry.cpp +61 -61
  38. package/example/android/app/src/main/jni/MainComponentsRegistry.h +32 -32
  39. package/example/android/app/src/main/jni/OnLoad.cpp +11 -11
  40. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -36
  41. package/example/android/app/src/main/res/values/strings.xml +3 -3
  42. package/example/android/app/src/main/res/values/styles.xml +9 -9
  43. package/example/android/build.gradle +73 -73
  44. package/example/android/gradle/wrapper/gradle-wrapper.properties +5 -5
  45. package/example/android/gradle.properties +40 -40
  46. package/example/android/gradlew +234 -234
  47. package/example/android/local.properties +8 -0
  48. package/example/android/settings.gradle +11 -11
  49. package/example/app.json +3 -3
  50. package/example/babel.config.js +3 -3
  51. package/example/index.js +9 -9
  52. package/example/ios/Podfile +44 -44
  53. package/example/ios/Podfile.lock +561 -561
  54. package/example/ios/_xcode.env +11 -11
  55. package/example/ios/example/AppDelegate.h +8 -8
  56. package/example/ios/example/AppDelegate.mm +174 -174
  57. package/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json +53 -53
  58. package/example/ios/example/Images.xcassets/Contents.json +6 -6
  59. package/example/ios/example/Info.plist +62 -62
  60. package/example/ios/example/LaunchScreen.storyboard +47 -47
  61. package/example/ios/example/example.entitlements +8 -8
  62. package/example/ios/example/main.m +10 -10
  63. package/example/ios/example.xcodeproj/project.pbxproj +712 -712
  64. package/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme +88 -88
  65. package/example/ios/example.xcworkspace/contents.xcworkspacedata +10 -10
  66. package/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  67. package/example/ios/exampleTests/Info.plist +24 -24
  68. package/example/ios/exampleTests/exampleTests.m +66 -66
  69. package/example/metro.config.js +17 -17
  70. package/example/package.json +36 -36
  71. package/example/yarn.lock +7713 -7176
  72. package/index.js +520 -485
  73. package/ios/AppICEReactEvent.h +23 -23
  74. package/ios/AppICEReactEvent.m +86 -86
  75. package/ios/AppIceReactPlugin.h +59 -59
  76. package/ios/AppIceReactPlugin.m +641 -641
  77. package/ios/AppIceReactPlugin.xcodeproj/project.pbxproj +364 -364
  78. package/ios/AppIceReactPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -4
  79. package/ios/AppIceReactPlugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  80. package/ios/AppIceReactPlugin.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  81. package/ios/AppIceReactPlugin.xcodeproj/xcuserdata/artherajesh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  82. package/ios/AppIceReactPlugin.xcworkspace/contents.xcworkspacedata +10 -10
  83. package/ios/AppIceReactPlugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  84. package/ios/Podfile +10 -10
  85. package/ios/Podfile.lock +3 -3
  86. package/ios/Pods/Manifest.lock +3 -3
  87. package/ios/Pods/Pods.xcodeproj/project.pbxproj +395 -395
  88. package/ios/Pods/Pods.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/Pods-AppIceReactPlugin.xcscheme +58 -58
  89. package/ios/Pods/Pods.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/xcschememanagement.plist +18 -18
  90. package/ios/Pods/Pods.xcodeproj/xcuserdata/artherajesh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  91. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-Info.plist +26 -26
  92. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-acknowledgements.markdown +3 -3
  93. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-acknowledgements.plist +29 -29
  94. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-dummy.m +5 -5
  95. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-umbrella.h +16 -16
  96. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.debug.xcconfig +6 -6
  97. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.modulemap +6 -6
  98. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.release.xcconfig +6 -6
  99. package/package.json +41 -41
  100. package/reactnative-plugin-appice.podspec +30 -30
  101. package/example/android/.gradle/7.3.3/checksums/checksums.lock +0 -0
  102. package/example/android/.gradle/7.3.3/fileChanges/last-build.bin +0 -0
  103. package/example/android/.gradle/7.3.3/fileHashes/fileHashes.lock +0 -0
  104. package/example/android/.gradle/vcs-1/gc.properties +0 -0
  105. /package/{example/android/.gradle/7.3.3/gc.properties → android/src/main/test} +0 -0
@@ -1,641 +1,641 @@
1
- #import "AppIceReactPlugin.h"
2
- #import "AppICEReactEvent.h"
3
- #import "React/RCTLog.h"
4
- #import "appICE.h"
5
- #import "appICEUserDetails.h"
6
- #import "AppICEInboxMessage.h"
7
- #import <UserNotifications/UserNotifications.h>
8
- @implementation AppIceReactPlugin
9
-
10
- static BOOL isAppInitialized = NO;
11
- static NSDictionary *pendingDeeplink = nil;
12
-
13
- RCT_EXPORT_MODULE()
14
- + (BOOL)requiresMainQueueSetup {
15
- return NO;
16
- }
17
-
18
- - (NSDictionary *)constantsToExport {
19
- FIRST_SEEN = CustomUserPropertyConstants.FIRST_SEEN;
20
- LAST_SEEN = CustomUserPropertyConstants.LAST_SEEN;
21
- TOP_N_PRODUCTS_VIEWED = CustomUserPropertyConstants.TOP_N_PRODUCTS_VIEWED;
22
- N_COMPLAINTS_RAISED = CustomUserPropertyConstants.N_COMPLAINTS_RAISED;
23
- PREF_LOGIN_DEVICE = CustomUserPropertyConstants.PREF_LOGIN_DEVICE;
24
- REFERRAL_CAMPAIGN = CustomUserPropertyConstants.REFERRAL_CAMPAIGN;
25
- TOTAL_ORDER_VALUE = Ecommerce.TOTAL_ORDER_VALUE;
26
- ADD_TO_CART_N_DAYS = Ecommerce.ADD_TO_CART_N_DAYS;
27
- CREDIT_SCORE = FinancialServices.CREDIT_SCORE;
28
- DEBT_TO_INCOME_RATIO = FinancialServices.DEBT_TO_INCOME_RATIO;
29
- SAVINGS_BALANCE = FinancialServices.SAVINGS_BALANCE;
30
- CHECKING_BALANCE = FinancialServices.CHECKING_BALANCE;
31
- AVERAGE_TRANSACTION_AMOUNT = FinancialServices.AVERAGE_TRANSACTION_AMOUNT;
32
- FREQUENCY_OF_TRANSACTION = FinancialServices.FREQUENCY_OF_TRANSACTION;
33
- TYPE_OF_TRANSACTION = FinancialServices.TYPE_OF_TRANSACTION;
34
- return @{
35
- kAppICEPushNotificationClicked : kAppICEPushNotificationClicked,
36
- kAppICEInAppClicked : kAppICEInAppClicked,
37
- kn : @"n",
38
- kem : @"e",
39
- kph : @"p",
40
- ka : @"a",
41
- kg : @"g",
42
- ked : @"edt",
43
- ket : @"emt",
44
- km : @"m",
45
- kis_emp : @"em",
46
- kdob: @"d",
47
-
48
- INBOX_MESSAGE : @"message",
49
- INBOX_TITLE : @"title",
50
- INBOX_MESSAGE_STATUS : @"messageStatus",
51
- INBOX_CAMPAIGN_TYPE : @"campType",
52
- INBOX_MESSAGE_LANGUAGE : @"messageLanguage",
53
- INBOX_MESSAGE_ID : @"id",
54
- INBOX_CAMPAIGN_ID : @"campId",
55
- INBOX_MESSAGE_CATEGORY : @"category",
56
- INBOX_MESSAGE_ICON : @"icon",
57
- INBOX_CUSTOM_DATA : @"cdata",
58
- INBOX_MESSAGE_EXPANDED_IMAGE :@"eni",
59
-
60
- DEMOGRAPHIC_INFO :@"customProperties",
61
- @"TOP_N_PRODUCTS_VIEWED" : TOP_N_PRODUCTS_VIEWED,
62
- @"N_COMPLAINTS_RAISED" : N_COMPLAINTS_RAISED,
63
- @"PREF_LOGIN_DEVICE" : PREF_LOGIN_DEVICE,
64
- @"REFERRAL_CAMPAIGN" : REFERRAL_CAMPAIGN,
65
- @"FIRST_SEEN" : FIRST_SEEN,
66
- @"LAST_SEEN" : LAST_SEEN,
67
-
68
- @"TOTAL_ORDER_VALUE" : TOTAL_ORDER_VALUE,
69
- @"ADD_TO_CART_N_DAYS" : ADD_TO_CART_N_DAYS,
70
-
71
- @"CREDIT_SCORE" : CREDIT_SCORE,
72
- @"DEBT_TO_INCOME_RATIO" : DEBT_TO_INCOME_RATIO,
73
- @"SAVINGS_BALANCE" : SAVINGS_BALANCE,
74
- @"CHECKING_BALANCE" : CHECKING_BALANCE,
75
- @"AVERAGE_TRANSACTION_AMOUNT" : AVERAGE_TRANSACTION_AMOUNT,
76
- @"FREQUENCY_OF_TRANSACTION": FREQUENCY_OF_TRANSACTION,
77
- @"TYPE_OF_TRANSACTION" : TYPE_OF_TRANSACTION
78
- };
79
- }
80
- - (dispatch_queue_t)methodQueue {
81
- return dispatch_get_main_queue();
82
- }
83
- RCT_EXPORT_METHOD(sampleMethod:(NSString *)stringArgument numberParameter:(nonnull NSNumber *)numberArgument callback:(RCTResponseSenderBlock)callback)
84
- {
85
- // TODO: Implement some actually useful functionality
86
- callback(@[[NSString stringWithFormat: @"numberArgument: %@ stringArgument: %@", numberArgument, stringArgument]]);
87
- }
88
-
89
- RCT_EXPORT_METHOD(startContext:(NSString *)appID
90
- withAppKey:(NSString *)appKey
91
- withApiKey:(NSString *)apiKey
92
- withDeviceId:(NSString *)deviceId
93
- region:(NSString *)region
94
- baseUrl:(NSString *)baseUrl
95
- certs : (NSArray *) certs)
96
- {
97
- [appICE setupKeys:appKey withapiKey:apiKey withappId:appID otherSdkdeviceId:deviceId region:region baseUrl:baseUrl certficates:certs];
98
-
99
-
100
- [[appICE sharedInstance] startContext];
101
- RCTLogInfo(@"App Ice SDK startContext");
102
-
103
- //sending device token after setupkets and startContext , else baseurl is not set and throw in putapp loop with null url
104
- if([[NSUserDefaults standardUserDefaults]objectForKey:kappICEToken])
105
- {
106
- [appICE setTokenInPushNotification:[[NSUserDefaults standardUserDefaults]objectForKey:kappICEToken]];
107
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:kappICEToken];
108
- }
109
- [self setClickCallback];
110
- }
111
-
112
- /**
113
- * didRegisterForRemoteNotificationsWithDeviceToken sets the device token in sdk or userdefaults depends upon sdk initalise.
114
- * @param deviceToken token in form of NSData
115
- * @discussion check if device token is not null and sdk is initalise , then pass device token to sdk
116
- * @discussion else save to userdefaults.
117
- */
118
- +(void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
119
- {
120
- RCTLog(@"token is : %@",deviceToken);
121
- if(deviceToken != NULL)
122
- {
123
- BOOL isInitialise = [[appICE sharedInstance]validateIntegration];
124
- if(isInitialise)
125
- {
126
- [appICE setTokenInPushNotification:deviceToken];
127
- }
128
- else{
129
- [[NSUserDefaults standardUserDefaults]setObject: deviceToken forKey:kappICEToken];
130
- }
131
- }
132
- }
133
-
134
- RCT_EXPORT_METHOD(tagEvent:(NSString*)eventName withProps:(NSDictionary*)props)
135
- {
136
- if (props == NULL) {
137
- [[appICE sharedInstance] recordEvent:eventName count:1];
138
-
139
- }else{
140
- [[appICE sharedInstance] recordEvent:eventName segmentation:props count:1];
141
- }
142
-
143
- }
144
-
145
- RCT_EXPORT_METHOD(setCustomVariable:(NSString*)eventName withStringValue:(NSString*)value)
146
- {
147
- [[appICE sharedInstance]setCustomVariable:eventName withStringValue:value];
148
-
149
- }
150
-
151
- RCT_EXPORT_METHOD(setUserId:(NSArray*)userIdArray)
152
- {
153
- [[appICE sharedInstance] setUserId:userIdArray];
154
- }
155
-
156
- /**
157
- * Call the native method to getUserId
158
- * Check if the getUserIdArray is not nil and the callback function is provided
159
- * else Handle the case when getUserIdArray is nil
160
- * Invoke the callback with an array containing NSNull to represent nil
161
- */
162
-
163
- RCT_EXPORT_METHOD(getUserId:(RCTResponseSenderBlock)callback)
164
- {
165
-
166
- NSMutableArray *getUserIdArray = [[appICE sharedInstance] getUserId];
167
- RCTLog(@"getUserIdArray %@", getUserIdArray);
168
-
169
- if (getUserIdArray && getUserIdArray.count > 0 && callback) {
170
- callback(@[getUserIdArray]);
171
- } else {
172
- if (callback) {
173
- callback(@[[NSNull null]]);
174
- }
175
- }
176
-
177
- }
178
-
179
- RCT_EXPORT_METHOD(pushNotificationClicked:(NSDictionary*)userInfo)
180
- {
181
- [[appICE sharedInstance] pushNotificationClickedEvent:userInfo];
182
- }
183
-
184
- RCT_EXPORT_METHOD(setUser:(NSDictionary*)userProfile)
185
- {
186
- NSArray *items = [NSArray arrayWithObjects:kAIUserName,kAIUserEmail,kAIUserPhone,kAIUserGender,kAIUserBirthYear,kAIUserAge,kAIUserIsUserEmployed,kAIUserEmploymentType,kAIUserEducationType,kAIUserIsUserMarried, nil];
187
- appICEUserDetails *app=[appICEUserDetails new];
188
- for(int i= 0; i< items.count ;i++)
189
- {
190
-
191
- if ([userProfile objectForKey:items[i]]) {
192
- switch (i) {
193
- case 0:
194
- app.name = userProfile[items[i]];
195
- break;
196
- case 1:
197
- app.email = userProfile[items[i]];
198
- break;
199
- case 2:
200
- app.phone = userProfile[items[i]];
201
- break;
202
- case 3:
203
- app.gender = userProfile[items[i]];
204
- break;
205
- case 4:
206
- app.dob = [userProfile[items[i]]longLongValue];
207
- break;
208
- case 5:
209
- app.age = [userProfile[items[i] ]intValue];
210
- break;
211
- case 6:
212
- app.is_user_employed = [userProfile[items[i]]boolValue];
213
- break;
214
- case 7:
215
- app.employment_type = userProfile[items[i]];
216
- break;
217
- case 8:
218
- app.education_type = userProfile[items[i]];
219
- break;
220
- case 9:
221
- app.is_user_married = [userProfile[items[i]]boolValue];
222
- break;
223
- default:
224
- break;
225
- }
226
- }
227
- }
228
- if(app != nil)
229
- {
230
- [[appICE sharedInstance] setUserDetail:app];
231
- }
232
-
233
- }
234
-
235
- /*===========================
236
- PushNotificationClicked
237
- * when Called ie. in Foreground and BG state isAppInitialized will be true and deeplink will be handled.
238
- * when Called in killed state isAppInitialized will be false and deeplink is stored and will be handled after the App is initialized.
239
- ===========================*/
240
-
241
- + (void)pushNotificationClicked:(NSDictionary *)userInfo {
242
- @try {
243
-
244
- if (!isAppInitialized) {
245
- RCTLog(@"Deeplink Push : not isAppInitialized" );
246
- // App is not initialized, store the deeplink for later processing
247
- [self storePendingDeeplink:userInfo];
248
- } else {
249
- // App is initialized, handle deeplinks in the click handler
250
- RCTLog(@"Deeplink Push : pushNotificationClicked deeplink handled" );
251
- [self storePendingDeeplink:userInfo];
252
- [self processPendingDeeplink];
253
- }
254
-
255
- NSDictionary *event = @{ kAppICEPushNotificationClicked : userInfo};
256
- [[NSNotificationCenter defaultCenter] postNotificationName:kAppICEPushNotificationClicked object:nil userInfo:event];
257
- } @catch (NSException *exception) {
258
- RCTLog(@"Deeplink Push : pushNotificationClicked exception %@",exception);
259
- }
260
-
261
- }
262
-
263
- RCT_EXPORT_METHOD(inAppClicked:(NSDictionary*)userInfo)
264
- {
265
- RCTLog(@"from inAppClicked method = %@",userInfo);
266
- }
267
-
268
- /*===========================
269
- PushNotificationReceived
270
- ===========================*/
271
- + (void)pushNotificationReceived:(NSDictionary *)userInfo {
272
- [[appICE sharedInstance]pushNotificationReceived:userInfo];
273
- }
274
-
275
- //InApp Deeplink Callback
276
- - (void)setClickCallback
277
- {
278
- [[appICE sharedInstance] setClickCallback:^(NSDictionary * _Nonnull cData) {
279
- if (cData != nil || cData.count > 0) {
280
- RCTLog(@"***** INapp success *** %@", cData);
281
- [[NSNotificationCenter defaultCenter] postNotificationName:kAppICEInAppClicked object:nil userInfo:cData];
282
-
283
- }
284
-
285
- }];
286
-
287
- }
288
- RCT_EXPORT_METHOD(setInternalId:(NSString*) internalId)
289
- {
290
- [[appICE sharedInstance] setInternalId:internalId];
291
- }
292
-
293
- /**
294
- * Call the native method to getDeviceId
295
- * Check if the internal ID is not nil and the callback function is provided
296
- * else Handle the case when getDeviceId is nil
297
- * Invoke the callback with an array containing NSNull to represent nil
298
- */
299
- RCT_EXPORT_METHOD(getDeviceId:(RCTResponseSenderBlock)callback)
300
- {
301
- NSString *getinternalId = [[appICE sharedInstance] getInternalId];
302
- RCTLog(@"getinternalID %@", getinternalId);
303
-
304
- if (getinternalId != nil && callback) {
305
- callback(@[getinternalId]);
306
- } else {
307
- if (callback) {
308
- callback(@[[NSNull null]]);
309
- }
310
- }
311
- }
312
-
313
- /**
314
- * Get inbox messages list.
315
- * @param type the message type
316
- * 1 = ALL
317
- * 2 = UNREAD
318
- * 3 = READ
319
- * 4 = VIEWED
320
- * 5 = DELETED
321
- * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
322
- * @callback will have the string json array
323
- */
324
-
325
- RCT_EXPORT_METHOD(getInboxMessages:(int)type userId:(NSArray*)userIds callback:(RCTResponseSenderBlock)callback)
326
- {
327
- NSMutableArray *inboxMessagesArray = [[appICE sharedInstance] getInboxMessages:type userId:userIds];
328
- // Convert AppICEInboxMessage objects to dictionaries
329
-
330
- NSMutableArray *formattedinboxMessages = [NSMutableArray array];
331
- for (AppICEInboxMessage *inboxMessage in inboxMessagesArray) {
332
- NSDictionary *formattedMessage = [self formatInboxMessage:inboxMessage];
333
- [formattedinboxMessages addObject:formattedMessage];
334
- }
335
- RCTLog(@"Formatted Inbox Messages: %@", formattedinboxMessages);
336
- [self returnResult:formattedinboxMessages withCallback:callback andError:nil];
337
-
338
- }
339
-
340
- /**
341
- ---------------
342
- APPINBOX
343
- ---------------
344
- * Get inbox messages count.
345
- * @param type the message type
346
- * 1 = ALL
347
- * 2 = UNREAD
348
- * 3 = READ
349
- * 4 = VIEWED
350
- * 5 = DELETED
351
- * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
352
- * @callback will have the integer
353
- */
354
-
355
- RCT_EXPORT_METHOD(getMessageCount:(int)type userId:(NSArray*)userId callback:(RCTResponseSenderBlock)callback)
356
- {
357
- int inboxMessageCount = [[appICE sharedInstance] getMessageCount:type userId:userId];
358
- RCTLog(@"Inbox Messages Count: %d", inboxMessageCount);
359
-
360
- [self returnResult:@(inboxMessageCount) withCallback:callback andError:nil];
361
- }
362
-
363
- /**
364
- * Get messages payload based on message id.
365
- * @param messageId - message id of the notification
366
- * @param userId - single userid in string ie. "useridA"
367
- * @callback will have the json object
368
- */
369
- RCT_EXPORT_METHOD(getInboxMessageForId:(NSString*)messageId userId:(NSString*)userId callback:(RCTResponseSenderBlock)callback)
370
- {
371
-
372
- AppICEInboxMessage *inboxMessageId = [[appICE sharedInstance] getInboxMessageForId:messageId usrId:userId];
373
- RCTLog(@"Inbox Messages id: %@", inboxMessageId);
374
- NSDictionary *formattedMessageforId = [self formatInboxMessage:inboxMessageId];
375
- RCTLog(@"Formatted Inbox Message id: %@", formattedMessageforId);
376
-
377
- [self returnResult:formattedMessageforId withCallback:callback andError:nil];
378
- }
379
-
380
- /**
381
- * update message status ex. UNREAD to READ.
382
- * @param messageId - message id of the notification
383
- * @param type - integer value for status
384
- * @param userId - single userid in string
385
- * @callback will have the boolean
386
- */
387
-
388
- RCT_EXPORT_METHOD(updateInboxMessage:(NSString *)messageId type:(int)type userId:(NSString *)userId callback:(RCTResponseSenderBlock)callback)
389
- {
390
- BOOL isSuccess = [[appICE sharedInstance] updateInboxMessage:type messageId:messageId userid:userId];
391
- RCTLog(@"Update Inbox Message Success: %@", isSuccess ? @"YES" : @"NO");
392
-
393
- [self returnResult:@(isSuccess) withCallback:callback andError:nil];
394
- }
395
-
396
- /**
397
- * synchronizeInbox message Ttue or False.
398
- * @param timeout - integer value
399
- * @callback will have the boolean
400
- */
401
- RCT_EXPORT_METHOD(synchronizeInbox:(int)timeout callback:(RCTResponseSenderBlock)callback)
402
- {
403
- // Save the callback for later use
404
- RCTLog(@"synchronizeInbox");
405
-
406
- [[appICE sharedInstance] synchronizeInbox:^(BOOL success) {
407
-
408
- [self returnResult:@(success) withCallback:callback andError:nil];
409
-
410
- } timeoutinSec:timeout];
411
-
412
- }
413
-
414
- // Add a method to format AppICEInboxMessage to a dictionary
415
- - (NSDictionary *)formatInboxMessage:(AppICEInboxMessage *)inboxMessage {
416
- if (inboxMessage) {
417
- return @{
418
- @"messageId": inboxMessage.messageId,
419
- @"id": inboxMessage.messageMid,
420
- @"icon": inboxMessage.messageImage,
421
- @"message": inboxMessage.messageBody,
422
- @"title": inboxMessage.messageTitle,
423
- @"messageStatus": inboxMessage.messageStatus,
424
- @"messageLanguage": inboxMessage.messageLanguage,
425
- @"campId": inboxMessage.messageCampid,
426
- @"cdata": inboxMessage.customData,
427
- @"messageExpiryTime": @(inboxMessage.messageExpiryTime),
428
- @"campType": inboxMessage.campType,
429
- @"eni": inboxMessage.messageExpandedImage
430
- };
431
- } else {
432
- return @{};
433
- }
434
- }
435
- /**
436
- * GetUser Details
437
- * @callback will have the dictionary
438
- */
439
- RCT_EXPORT_METHOD(getUser:(RCTResponseSenderBlock)callback)
440
- {
441
- appICEUserDetails *app = [[appICE sharedInstance] getUserDetail];
442
- NSDictionary *userDictionary = [app toDictionary];
443
- NSLog(@"getUserDetails: %@", userDictionary);
444
- [self returnResult:userDictionary withCallback:callback andError:nil];
445
- }
446
-
447
- /**
448
- * RegisterLifeCycle
449
- */
450
- RCT_EXPORT_METHOD(registerLifeCycle) {
451
-
452
- // implementation to register the lifecycle
453
- }
454
-
455
- # pragma RichPush AppInbox
456
- /**
457
- * getMediaData
458
- * @param inboxMessageDict NSDictionary representing the inbox message data.
459
- * @param mediaKey NSString representing the key to fetch media data from the inbox message.
460
- * @param callback RCTResponseSenderBlock callback function to return the media data.
461
- */
462
-
463
- RCT_EXPORT_METHOD(getMediaData:(NSDictionary *)inboxMessageDict mediaKey:(NSString *)mediaKey callback:(RCTResponseSenderBlock)callback)
464
- {
465
- AppICEInboxMessage *inboxMessageInstance = [AppICEInboxMessage instanceFromDictionary:inboxMessageDict];
466
- if (!inboxMessageInstance) {
467
- [self returnResult:@{} withCallback:callback andError:nil];
468
- return;
469
- }
470
- else{
471
- NSDictionary *mediaData = [inboxMessageInstance mediaData:mediaKey];
472
- if (mediaData) {
473
- [self returnResult:mediaData withCallback:callback andError:nil];
474
- } else {
475
- [self returnResult:@{} withCallback:callback andError:nil];
476
- }
477
- }
478
- }
479
-
480
- /**
481
- * getMediaUrl
482
- * @param mediaData NSMutableDictionary get the mediaData Dictionary
483
- * @param callback RCTResponseSenderBlock callback function to return the media data.
484
- */
485
- RCT_EXPORT_METHOD(getMediaUrl:(NSDictionary *)inboxMessageDict mediaData:(NSDictionary*)mediaData callback:(RCTResponseSenderBlock)callback)
486
- {
487
- AppICEInboxMessage *inboxMessageInstance = [AppICEInboxMessage instanceFromDictionary:inboxMessageDict];
488
- if (!inboxMessageInstance) {
489
- [self returnResult:@{} withCallback:callback andError:nil];
490
- return;
491
- }
492
- NSString *mediaUrl = [inboxMessageInstance mediaUrl:mediaData];
493
- [self returnResult:mediaUrl withCallback:callback andError:nil];
494
- }
495
-
496
- /**
497
- * mediaType for AppInbox
498
- * @param mediaData NSMutableDictionary get the mediaData Dictionary
499
- * @callback mediaType as 'image' or 'animated' or 'video'
500
- */
501
- RCT_EXPORT_METHOD(getMediaType:(NSDictionary *)inboxMessageDict mediaData:(NSDictionary*)mediaData callback:(RCTResponseSenderBlock)callback)
502
- {
503
- AppICEInboxMessage *inboxMessageInstance = [AppICEInboxMessage instanceFromDictionary:inboxMessageDict];
504
- if (!inboxMessageInstance) {
505
- [self returnResult:@{} withCallback:callback andError:nil];
506
- return;
507
- }
508
- NSString *mediaType = [inboxMessageInstance mediaType:mediaData];
509
- [self returnResult:mediaType withCallback:callback andError:nil];
510
- }
511
-
512
- /**
513
- * mediaThumbnail for AppInbox
514
- * @param mediaData NSMutableDictionary get the mediaData Dictionary
515
- * @callback mediaThumbnail as string
516
- */
517
- RCT_EXPORT_METHOD(getMediaThumbnail:(NSDictionary *)inboxMessageDict mediaData:(NSDictionary*)mediaData callback:(RCTResponseSenderBlock)callback)
518
- {
519
- AppICEInboxMessage *inboxMessageInstance = [AppICEInboxMessage instanceFromDictionary:inboxMessageDict];
520
- if (!inboxMessageInstance) {
521
- [self returnResult:@{} withCallback:callback andError:nil];
522
- return;
523
- }
524
- NSString *mediaThumbnail = [inboxMessageInstance mediaThumbnail:mediaData];
525
- [self returnResult:mediaThumbnail withCallback:callback andError:nil];
526
- }
527
-
528
- # pragma RichPush Push DeepLink Handling
529
-
530
- /*----------------------------------------------------------------------------
531
- storePendingDeeplink
532
- * @param userInfo - NSDictionary
533
- * Store the pending deeplink info in the static variable for later processing
534
- -----------------------------------------------------------------------------*/
535
- + (void)storePendingDeeplink:(NSDictionary *)userInfo {
536
- @try {
537
- // Store the pending deeplink info in the static variable for later processing
538
- pendingDeeplink = userInfo;
539
- RCTLog(@"Deeplink Push : storePendingDeeplink called" );
540
- } @catch (NSException *exception) {
541
- RCTLog(@"Deeplink Push : storePendingDeeplink exception %@",exception);
542
- }
543
- }
544
-
545
- /*----------------------------------------------------------------------------
546
- processPendingDeeplink
547
- * Process the pending deeplink if it exists and the app is initialized
548
- * Clear the pending deeplink after processing
549
- -----------------------------------------------------------------------------*/
550
- + (void)processPendingDeeplink {
551
- @try {
552
-
553
- RCTLog(@"Deeplink Push : processPendingDeeplink called isAppInitialized: %d , pendingDeeplink: %@",isAppInitialized,pendingDeeplink);
554
- if (isAppInitialized && pendingDeeplink) {
555
- RCTLog(@"Deeplink Push : handled in stored data");
556
- [[appICE sharedInstance] handleClickOnPush:pendingDeeplink OpenDeepLink:YES];
557
- pendingDeeplink = nil;
558
- }
559
- } @catch (NSException *exception) {
560
- RCTLog(@"Deeplink Push : processPendingDeeplink exception %@",exception);
561
- } @finally {
562
- pendingDeeplink = nil;
563
- RCTLog(@"Deeplink Push : finally processPendingDeeplink pendingDeeplink set as nil");
564
- }
565
-
566
- }
567
-
568
- /*------------------------------------------------------
569
- isDeviceReady
570
- * @param isDeviceReady - BOOL
571
- * Set the flag to indicate that the app is initialized
572
- * Process any pending deeplinks after initialization
573
- ------------------------------------------------------*/
574
- RCT_EXPORT_METHOD(isDeviceReady: (BOOL)isActive)
575
- {
576
-
577
- RCTLog(@"Deeplink Push : isDeviceReady called state = %d",isActive );
578
- if(isActive)
579
- {
580
- isAppInitialized = YES;
581
- [AppIceReactPlugin processPendingDeeplink];
582
- }
583
- else
584
- {
585
- isAppInitialized = NO;
586
- }
587
- }
588
-
589
- #pragma GETUSER WITH ARRAY
590
-
591
- /*--------------------------------------------
592
- * synchronizeData message True or False.
593
- * @param timeout as int
594
- * @callback will have the boolean
595
- ---------------------------------------------*/
596
- RCT_EXPORT_METHOD(synchronizeData:(int)timeout callback:(RCTResponseSenderBlock)callback)
597
- {
598
- // Save the callback for later use
599
- RCTLog(@"GETUSER: synchronizeData");
600
- [[appICE sharedInstance] synchronizeData:^(BOOL success) {
601
- [self returnResult:@(success) withCallback:callback andError:nil];
602
- }timeoutinSec:timeout];
603
- }
604
-
605
- /*--------------------------------------------
606
- * getUserForIds with UserId
607
- * userIds - NSArray
608
- * @callback will have the boolean
609
- ---------------------------------------------*/
610
-
611
- RCT_EXPORT_METHOD(getUserForIds:(NSArray*)userIds callback:(RCTResponseSenderBlock)callback)
612
- {
613
- NSMutableArray *getUserArray =[[appICEUserDetails sharedUserDetails] getUser:userIds];
614
- // Convert appICEUserDetails objects to dictionaries
615
-
616
- NSMutableArray *formattedGetUser = [NSMutableArray array];
617
- for (appICEUserDetails *getUserData in getUserArray) {
618
- NSDictionary *formattedMessage = [getUserData toDictionary];
619
- [formattedGetUser addObject:formattedMessage];
620
- }
621
- RCTLog(@"GETUSER: Formatted getUser Messages: %@", formattedGetUser);
622
- [self returnResult:formattedGetUser withCallback:callback andError:nil];
623
-
624
- }
625
-
626
-
627
-
628
- - (void)returnResult:(id)result withCallback:(RCTResponseSenderBlock)callback andError:(NSString *)error {
629
-
630
- if (callback == nil) {
631
- RCTLog(@"AppICE:callback was nil");
632
- return;
633
- }
634
- // id e = error != nil ? error : [NSNull null];
635
- id r = result != nil ? result : [NSNull null];
636
- RCTLog(@"AppICE: result: %@",r);
637
- callback(@[r]);
638
- }
639
-
640
- @end
641
-
1
+ #import "AppIceReactPlugin.h"
2
+ #import "AppICEReactEvent.h"
3
+ #import "React/RCTLog.h"
4
+ #import "appICE.h"
5
+ #import "appICEUserDetails.h"
6
+ #import "AppICEInboxMessage.h"
7
+ #import <UserNotifications/UserNotifications.h>
8
+ @implementation AppIceReactPlugin
9
+
10
+ static BOOL isAppInitialized = NO;
11
+ static NSDictionary *pendingDeeplink = nil;
12
+
13
+ RCT_EXPORT_MODULE()
14
+ + (BOOL)requiresMainQueueSetup {
15
+ return NO;
16
+ }
17
+
18
+ - (NSDictionary *)constantsToExport {
19
+ FIRST_SEEN = CustomUserPropertyConstants.FIRST_SEEN;
20
+ LAST_SEEN = CustomUserPropertyConstants.LAST_SEEN;
21
+ TOP_N_PRODUCTS_VIEWED = CustomUserPropertyConstants.TOP_N_PRODUCTS_VIEWED;
22
+ N_COMPLAINTS_RAISED = CustomUserPropertyConstants.N_COMPLAINTS_RAISED;
23
+ PREF_LOGIN_DEVICE = CustomUserPropertyConstants.PREF_LOGIN_DEVICE;
24
+ REFERRAL_CAMPAIGN = CustomUserPropertyConstants.REFERRAL_CAMPAIGN;
25
+ TOTAL_ORDER_VALUE = Ecommerce.TOTAL_ORDER_VALUE;
26
+ ADD_TO_CART_N_DAYS = Ecommerce.ADD_TO_CART_N_DAYS;
27
+ CREDIT_SCORE = FinancialServices.CREDIT_SCORE;
28
+ DEBT_TO_INCOME_RATIO = FinancialServices.DEBT_TO_INCOME_RATIO;
29
+ SAVINGS_BALANCE = FinancialServices.SAVINGS_BALANCE;
30
+ CHECKING_BALANCE = FinancialServices.CHECKING_BALANCE;
31
+ AVERAGE_TRANSACTION_AMOUNT = FinancialServices.AVERAGE_TRANSACTION_AMOUNT;
32
+ FREQUENCY_OF_TRANSACTION = FinancialServices.FREQUENCY_OF_TRANSACTION;
33
+ TYPE_OF_TRANSACTION = FinancialServices.TYPE_OF_TRANSACTION;
34
+ return @{
35
+ kAppICEPushNotificationClicked : kAppICEPushNotificationClicked,
36
+ kAppICEInAppClicked : kAppICEInAppClicked,
37
+ kn : @"n",
38
+ kem : @"e",
39
+ kph : @"p",
40
+ ka : @"a",
41
+ kg : @"g",
42
+ ked : @"edt",
43
+ ket : @"emt",
44
+ km : @"m",
45
+ kis_emp : @"em",
46
+ kdob: @"d",
47
+
48
+ INBOX_MESSAGE : @"message",
49
+ INBOX_TITLE : @"title",
50
+ INBOX_MESSAGE_STATUS : @"messageStatus",
51
+ INBOX_CAMPAIGN_TYPE : @"campType",
52
+ INBOX_MESSAGE_LANGUAGE : @"messageLanguage",
53
+ INBOX_MESSAGE_ID : @"id",
54
+ INBOX_CAMPAIGN_ID : @"campId",
55
+ INBOX_MESSAGE_CATEGORY : @"category",
56
+ INBOX_MESSAGE_ICON : @"icon",
57
+ INBOX_CUSTOM_DATA : @"cdata",
58
+ INBOX_MESSAGE_EXPANDED_IMAGE :@"eni",
59
+
60
+ DEMOGRAPHIC_INFO :@"customProperties",
61
+ @"TOP_N_PRODUCTS_VIEWED" : TOP_N_PRODUCTS_VIEWED,
62
+ @"N_COMPLAINTS_RAISED" : N_COMPLAINTS_RAISED,
63
+ @"PREF_LOGIN_DEVICE" : PREF_LOGIN_DEVICE,
64
+ @"REFERRAL_CAMPAIGN" : REFERRAL_CAMPAIGN,
65
+ @"FIRST_SEEN" : FIRST_SEEN,
66
+ @"LAST_SEEN" : LAST_SEEN,
67
+
68
+ @"TOTAL_ORDER_VALUE" : TOTAL_ORDER_VALUE,
69
+ @"ADD_TO_CART_N_DAYS" : ADD_TO_CART_N_DAYS,
70
+
71
+ @"CREDIT_SCORE" : CREDIT_SCORE,
72
+ @"DEBT_TO_INCOME_RATIO" : DEBT_TO_INCOME_RATIO,
73
+ @"SAVINGS_BALANCE" : SAVINGS_BALANCE,
74
+ @"CHECKING_BALANCE" : CHECKING_BALANCE,
75
+ @"AVERAGE_TRANSACTION_AMOUNT" : AVERAGE_TRANSACTION_AMOUNT,
76
+ @"FREQUENCY_OF_TRANSACTION": FREQUENCY_OF_TRANSACTION,
77
+ @"TYPE_OF_TRANSACTION" : TYPE_OF_TRANSACTION
78
+ };
79
+ }
80
+ - (dispatch_queue_t)methodQueue {
81
+ return dispatch_get_main_queue();
82
+ }
83
+ RCT_EXPORT_METHOD(sampleMethod:(NSString *)stringArgument numberParameter:(nonnull NSNumber *)numberArgument callback:(RCTResponseSenderBlock)callback)
84
+ {
85
+ // TODO: Implement some actually useful functionality
86
+ callback(@[[NSString stringWithFormat: @"numberArgument: %@ stringArgument: %@", numberArgument, stringArgument]]);
87
+ }
88
+
89
+ RCT_EXPORT_METHOD(startContext:(NSString *)appID
90
+ withAppKey:(NSString *)appKey
91
+ withApiKey:(NSString *)apiKey
92
+ withDeviceId:(NSString *)deviceId
93
+ region:(NSString *)region
94
+ baseUrl:(NSString *)baseUrl
95
+ certs : (NSArray *) certs)
96
+ {
97
+ [appICE setupKeys:appKey withapiKey:apiKey withappId:appID otherSdkdeviceId:deviceId region:region baseUrl:baseUrl certficates:certs];
98
+
99
+
100
+ [[appICE sharedInstance] startContext];
101
+ RCTLogInfo(@"App Ice SDK startContext");
102
+
103
+ //sending device token after setupkets and startContext , else baseurl is not set and throw in putapp loop with null url
104
+ if([[NSUserDefaults standardUserDefaults]objectForKey:kappICEToken])
105
+ {
106
+ [appICE setTokenInPushNotification:[[NSUserDefaults standardUserDefaults]objectForKey:kappICEToken]];
107
+ [[NSUserDefaults standardUserDefaults] removeObjectForKey:kappICEToken];
108
+ }
109
+ [self setClickCallback];
110
+ }
111
+
112
+ /**
113
+ * didRegisterForRemoteNotificationsWithDeviceToken sets the device token in sdk or userdefaults depends upon sdk initalise.
114
+ * @param deviceToken token in form of NSData
115
+ * @discussion check if device token is not null and sdk is initalise , then pass device token to sdk
116
+ * @discussion else save to userdefaults.
117
+ */
118
+ +(void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
119
+ {
120
+ RCTLog(@"token is : %@",deviceToken);
121
+ if(deviceToken != NULL)
122
+ {
123
+ BOOL isInitialise = [[appICE sharedInstance]validateIntegration];
124
+ if(isInitialise)
125
+ {
126
+ [appICE setTokenInPushNotification:deviceToken];
127
+ }
128
+ else{
129
+ [[NSUserDefaults standardUserDefaults]setObject: deviceToken forKey:kappICEToken];
130
+ }
131
+ }
132
+ }
133
+
134
+ RCT_EXPORT_METHOD(tagEvent:(NSString*)eventName withProps:(NSDictionary*)props)
135
+ {
136
+ if (props == NULL) {
137
+ [[appICE sharedInstance] recordEvent:eventName count:1];
138
+
139
+ }else{
140
+ [[appICE sharedInstance] recordEvent:eventName segmentation:props count:1];
141
+ }
142
+
143
+ }
144
+
145
+ RCT_EXPORT_METHOD(setCustomVariable:(NSString*)eventName withStringValue:(NSString*)value)
146
+ {
147
+ [[appICE sharedInstance]setCustomVariable:eventName withStringValue:value];
148
+
149
+ }
150
+
151
+ RCT_EXPORT_METHOD(setUserId:(NSArray*)userIdArray)
152
+ {
153
+ [[appICE sharedInstance] setUserId:userIdArray];
154
+ }
155
+
156
+ /**
157
+ * Call the native method to getUserId
158
+ * Check if the getUserIdArray is not nil and the callback function is provided
159
+ * else Handle the case when getUserIdArray is nil
160
+ * Invoke the callback with an array containing NSNull to represent nil
161
+ */
162
+
163
+ RCT_EXPORT_METHOD(getUserId:(RCTResponseSenderBlock)callback)
164
+ {
165
+
166
+ NSMutableArray *getUserIdArray = [[appICE sharedInstance] getUserId];
167
+ RCTLog(@"getUserIdArray %@", getUserIdArray);
168
+
169
+ if (getUserIdArray && getUserIdArray.count > 0 && callback) {
170
+ callback(@[getUserIdArray]);
171
+ } else {
172
+ if (callback) {
173
+ callback(@[[NSNull null]]);
174
+ }
175
+ }
176
+
177
+ }
178
+
179
+ RCT_EXPORT_METHOD(pushNotificationClicked:(NSDictionary*)userInfo)
180
+ {
181
+ [[appICE sharedInstance] pushNotificationClickedEvent:userInfo];
182
+ }
183
+
184
+ RCT_EXPORT_METHOD(setUser:(NSDictionary*)userProfile)
185
+ {
186
+ NSArray *items = [NSArray arrayWithObjects:kAIUserName,kAIUserEmail,kAIUserPhone,kAIUserGender,kAIUserBirthYear,kAIUserAge,kAIUserIsUserEmployed,kAIUserEmploymentType,kAIUserEducationType,kAIUserIsUserMarried, nil];
187
+ appICEUserDetails *app=[appICEUserDetails new];
188
+ for(int i= 0; i< items.count ;i++)
189
+ {
190
+
191
+ if ([userProfile objectForKey:items[i]]) {
192
+ switch (i) {
193
+ case 0:
194
+ app.name = userProfile[items[i]];
195
+ break;
196
+ case 1:
197
+ app.email = userProfile[items[i]];
198
+ break;
199
+ case 2:
200
+ app.phone = userProfile[items[i]];
201
+ break;
202
+ case 3:
203
+ app.gender = userProfile[items[i]];
204
+ break;
205
+ case 4:
206
+ app.dob = [userProfile[items[i]]longLongValue];
207
+ break;
208
+ case 5:
209
+ app.age = [userProfile[items[i] ]intValue];
210
+ break;
211
+ case 6:
212
+ app.is_user_employed = [userProfile[items[i]]boolValue];
213
+ break;
214
+ case 7:
215
+ app.employment_type = userProfile[items[i]];
216
+ break;
217
+ case 8:
218
+ app.education_type = userProfile[items[i]];
219
+ break;
220
+ case 9:
221
+ app.is_user_married = [userProfile[items[i]]boolValue];
222
+ break;
223
+ default:
224
+ break;
225
+ }
226
+ }
227
+ }
228
+ if(app != nil)
229
+ {
230
+ [[appICE sharedInstance] setUserDetail:app];
231
+ }
232
+
233
+ }
234
+
235
+ /*===========================
236
+ PushNotificationClicked
237
+ * when Called ie. in Foreground and BG state isAppInitialized will be true and deeplink will be handled.
238
+ * when Called in killed state isAppInitialized will be false and deeplink is stored and will be handled after the App is initialized.
239
+ ===========================*/
240
+
241
+ + (void)pushNotificationClicked:(NSDictionary *)userInfo {
242
+ @try {
243
+
244
+ if (!isAppInitialized) {
245
+ RCTLog(@"Deeplink Push : not isAppInitialized" );
246
+ // App is not initialized, store the deeplink for later processing
247
+ [self storePendingDeeplink:userInfo];
248
+ } else {
249
+ // App is initialized, handle deeplinks in the click handler
250
+ RCTLog(@"Deeplink Push : pushNotificationClicked deeplink handled" );
251
+ [self storePendingDeeplink:userInfo];
252
+ [self processPendingDeeplink];
253
+ }
254
+
255
+ NSDictionary *event = @{ kAppICEPushNotificationClicked : userInfo};
256
+ [[NSNotificationCenter defaultCenter] postNotificationName:kAppICEPushNotificationClicked object:nil userInfo:event];
257
+ } @catch (NSException *exception) {
258
+ RCTLog(@"Deeplink Push : pushNotificationClicked exception %@",exception);
259
+ }
260
+
261
+ }
262
+
263
+ RCT_EXPORT_METHOD(inAppClicked:(NSDictionary*)userInfo)
264
+ {
265
+ RCTLog(@"from inAppClicked method = %@",userInfo);
266
+ }
267
+
268
+ /*===========================
269
+ PushNotificationReceived
270
+ ===========================*/
271
+ + (void)pushNotificationReceived:(NSDictionary *)userInfo {
272
+ [[appICE sharedInstance]pushNotificationReceived:userInfo];
273
+ }
274
+
275
+ //InApp Deeplink Callback
276
+ - (void)setClickCallback
277
+ {
278
+ [[appICE sharedInstance] setClickCallback:^(NSDictionary * _Nonnull cData) {
279
+ if (cData != nil || cData.count > 0) {
280
+ RCTLog(@"***** INapp success *** %@", cData);
281
+ [[NSNotificationCenter defaultCenter] postNotificationName:kAppICEInAppClicked object:nil userInfo:cData];
282
+
283
+ }
284
+
285
+ }];
286
+
287
+ }
288
+ RCT_EXPORT_METHOD(setInternalId:(NSString*) internalId)
289
+ {
290
+ [[appICE sharedInstance] setInternalId:internalId];
291
+ }
292
+
293
+ /**
294
+ * Call the native method to getDeviceId
295
+ * Check if the internal ID is not nil and the callback function is provided
296
+ * else Handle the case when getDeviceId is nil
297
+ * Invoke the callback with an array containing NSNull to represent nil
298
+ */
299
+ RCT_EXPORT_METHOD(getDeviceId:(RCTResponseSenderBlock)callback)
300
+ {
301
+ NSString *getinternalId = [[appICE sharedInstance] getInternalId];
302
+ RCTLog(@"getinternalID %@", getinternalId);
303
+
304
+ if (getinternalId != nil && callback) {
305
+ callback(@[getinternalId]);
306
+ } else {
307
+ if (callback) {
308
+ callback(@[[NSNull null]]);
309
+ }
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Get inbox messages list.
315
+ * @param type the message type
316
+ * 1 = ALL
317
+ * 2 = UNREAD
318
+ * 3 = READ
319
+ * 4 = VIEWED
320
+ * 5 = DELETED
321
+ * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
322
+ * @callback will have the string json array
323
+ */
324
+
325
+ RCT_EXPORT_METHOD(getInboxMessages:(int)type userId:(NSArray*)userIds callback:(RCTResponseSenderBlock)callback)
326
+ {
327
+ NSMutableArray *inboxMessagesArray = [[appICE sharedInstance] getInboxMessages:type userId:userIds];
328
+ // Convert AppICEInboxMessage objects to dictionaries
329
+
330
+ NSMutableArray *formattedinboxMessages = [NSMutableArray array];
331
+ for (AppICEInboxMessage *inboxMessage in inboxMessagesArray) {
332
+ NSDictionary *formattedMessage = [self formatInboxMessage:inboxMessage];
333
+ [formattedinboxMessages addObject:formattedMessage];
334
+ }
335
+ RCTLog(@"Formatted Inbox Messages: %@", formattedinboxMessages);
336
+ [self returnResult:formattedinboxMessages withCallback:callback andError:nil];
337
+
338
+ }
339
+
340
+ /**
341
+ ---------------
342
+ APPINBOX
343
+ ---------------
344
+ * Get inbox messages count.
345
+ * @param type the message type
346
+ * 1 = ALL
347
+ * 2 = UNREAD
348
+ * 3 = READ
349
+ * 4 = VIEWED
350
+ * 5 = DELETED
351
+ * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
352
+ * @callback will have the integer
353
+ */
354
+
355
+ RCT_EXPORT_METHOD(getMessageCount:(int)type userId:(NSArray*)userId callback:(RCTResponseSenderBlock)callback)
356
+ {
357
+ int inboxMessageCount = [[appICE sharedInstance] getMessageCount:type userId:userId];
358
+ RCTLog(@"Inbox Messages Count: %d", inboxMessageCount);
359
+
360
+ [self returnResult:@(inboxMessageCount) withCallback:callback andError:nil];
361
+ }
362
+
363
+ /**
364
+ * Get messages payload based on message id.
365
+ * @param messageId - message id of the notification
366
+ * @param userId - single userid in string ie. "useridA"
367
+ * @callback will have the json object
368
+ */
369
+ RCT_EXPORT_METHOD(getInboxMessageForId:(NSString*)messageId userId:(NSString*)userId callback:(RCTResponseSenderBlock)callback)
370
+ {
371
+
372
+ AppICEInboxMessage *inboxMessageId = [[appICE sharedInstance] getInboxMessageForId:messageId usrId:userId];
373
+ RCTLog(@"Inbox Messages id: %@", inboxMessageId);
374
+ NSDictionary *formattedMessageforId = [self formatInboxMessage:inboxMessageId];
375
+ RCTLog(@"Formatted Inbox Message id: %@", formattedMessageforId);
376
+
377
+ [self returnResult:formattedMessageforId withCallback:callback andError:nil];
378
+ }
379
+
380
+ /**
381
+ * update message status ex. UNREAD to READ.
382
+ * @param messageId - message id of the notification
383
+ * @param type - integer value for status
384
+ * @param userId - single userid in string
385
+ * @callback will have the boolean
386
+ */
387
+
388
+ RCT_EXPORT_METHOD(updateInboxMessage:(NSString *)messageId type:(int)type userId:(NSString *)userId callback:(RCTResponseSenderBlock)callback)
389
+ {
390
+ BOOL isSuccess = [[appICE sharedInstance] updateInboxMessage:type messageId:messageId userid:userId];
391
+ RCTLog(@"Update Inbox Message Success: %@", isSuccess ? @"YES" : @"NO");
392
+
393
+ [self returnResult:@(isSuccess) withCallback:callback andError:nil];
394
+ }
395
+
396
+ /**
397
+ * synchronizeInbox message Ttue or False.
398
+ * @param timeout - integer value
399
+ * @callback will have the boolean
400
+ */
401
+ RCT_EXPORT_METHOD(synchronizeInbox:(int)timeout callback:(RCTResponseSenderBlock)callback)
402
+ {
403
+ // Save the callback for later use
404
+ RCTLog(@"synchronizeInbox");
405
+
406
+ [[appICE sharedInstance] synchronizeInbox:^(BOOL success) {
407
+
408
+ [self returnResult:@(success) withCallback:callback andError:nil];
409
+
410
+ } timeoutinSec:timeout];
411
+
412
+ }
413
+
414
+ // Add a method to format AppICEInboxMessage to a dictionary
415
+ - (NSDictionary *)formatInboxMessage:(AppICEInboxMessage *)inboxMessage {
416
+ if (inboxMessage) {
417
+ return @{
418
+ @"messageId": inboxMessage.messageId,
419
+ @"id": inboxMessage.messageMid,
420
+ @"icon": inboxMessage.messageImage,
421
+ @"message": inboxMessage.messageBody,
422
+ @"title": inboxMessage.messageTitle,
423
+ @"messageStatus": inboxMessage.messageStatus,
424
+ @"messageLanguage": inboxMessage.messageLanguage,
425
+ @"campId": inboxMessage.messageCampid,
426
+ @"cdata": inboxMessage.customData,
427
+ @"messageExpiryTime": @(inboxMessage.messageExpiryTime),
428
+ @"campType": inboxMessage.campType,
429
+ @"eni": inboxMessage.messageExpandedImage
430
+ };
431
+ } else {
432
+ return @{};
433
+ }
434
+ }
435
+ /**
436
+ * GetUser Details
437
+ * @callback will have the dictionary
438
+ */
439
+ RCT_EXPORT_METHOD(getUser:(RCTResponseSenderBlock)callback)
440
+ {
441
+ appICEUserDetails *app = [[appICE sharedInstance] getUserDetail];
442
+ NSDictionary *userDictionary = [app toDictionary];
443
+ NSLog(@"getUserDetails: %@", userDictionary);
444
+ [self returnResult:userDictionary withCallback:callback andError:nil];
445
+ }
446
+
447
+ /**
448
+ * RegisterLifeCycle
449
+ */
450
+ RCT_EXPORT_METHOD(registerLifeCycle) {
451
+
452
+ // implementation to register the lifecycle
453
+ }
454
+
455
+ # pragma RichPush AppInbox
456
+ /**
457
+ * getMediaData
458
+ * @param inboxMessageDict NSDictionary representing the inbox message data.
459
+ * @param mediaKey NSString representing the key to fetch media data from the inbox message.
460
+ * @param callback RCTResponseSenderBlock callback function to return the media data.
461
+ */
462
+
463
+ RCT_EXPORT_METHOD(getMediaData:(NSDictionary *)inboxMessageDict mediaKey:(NSString *)mediaKey callback:(RCTResponseSenderBlock)callback)
464
+ {
465
+ AppICEInboxMessage *inboxMessageInstance = [AppICEInboxMessage instanceFromDictionary:inboxMessageDict];
466
+ if (!inboxMessageInstance) {
467
+ [self returnResult:@{} withCallback:callback andError:nil];
468
+ return;
469
+ }
470
+ else{
471
+ NSDictionary *mediaData = [inboxMessageInstance mediaData:mediaKey];
472
+ if (mediaData) {
473
+ [self returnResult:mediaData withCallback:callback andError:nil];
474
+ } else {
475
+ [self returnResult:@{} withCallback:callback andError:nil];
476
+ }
477
+ }
478
+ }
479
+
480
+ /**
481
+ * getMediaUrl
482
+ * @param mediaData NSMutableDictionary get the mediaData Dictionary
483
+ * @param callback RCTResponseSenderBlock callback function to return the media data.
484
+ */
485
+ RCT_EXPORT_METHOD(getMediaUrl:(NSDictionary *)inboxMessageDict mediaData:(NSDictionary*)mediaData callback:(RCTResponseSenderBlock)callback)
486
+ {
487
+ AppICEInboxMessage *inboxMessageInstance = [AppICEInboxMessage instanceFromDictionary:inboxMessageDict];
488
+ if (!inboxMessageInstance) {
489
+ [self returnResult:@{} withCallback:callback andError:nil];
490
+ return;
491
+ }
492
+ NSString *mediaUrl = [inboxMessageInstance mediaUrl:mediaData];
493
+ [self returnResult:mediaUrl withCallback:callback andError:nil];
494
+ }
495
+
496
+ /**
497
+ * mediaType for AppInbox
498
+ * @param mediaData NSMutableDictionary get the mediaData Dictionary
499
+ * @callback mediaType as 'image' or 'animated' or 'video'
500
+ */
501
+ RCT_EXPORT_METHOD(getMediaType:(NSDictionary *)inboxMessageDict mediaData:(NSDictionary*)mediaData callback:(RCTResponseSenderBlock)callback)
502
+ {
503
+ AppICEInboxMessage *inboxMessageInstance = [AppICEInboxMessage instanceFromDictionary:inboxMessageDict];
504
+ if (!inboxMessageInstance) {
505
+ [self returnResult:@{} withCallback:callback andError:nil];
506
+ return;
507
+ }
508
+ NSString *mediaType = [inboxMessageInstance mediaType:mediaData];
509
+ [self returnResult:mediaType withCallback:callback andError:nil];
510
+ }
511
+
512
+ /**
513
+ * mediaThumbnail for AppInbox
514
+ * @param mediaData NSMutableDictionary get the mediaData Dictionary
515
+ * @callback mediaThumbnail as string
516
+ */
517
+ RCT_EXPORT_METHOD(getMediaThumbnail:(NSDictionary *)inboxMessageDict mediaData:(NSDictionary*)mediaData callback:(RCTResponseSenderBlock)callback)
518
+ {
519
+ AppICEInboxMessage *inboxMessageInstance = [AppICEInboxMessage instanceFromDictionary:inboxMessageDict];
520
+ if (!inboxMessageInstance) {
521
+ [self returnResult:@{} withCallback:callback andError:nil];
522
+ return;
523
+ }
524
+ NSString *mediaThumbnail = [inboxMessageInstance mediaThumbnail:mediaData];
525
+ [self returnResult:mediaThumbnail withCallback:callback andError:nil];
526
+ }
527
+
528
+ # pragma RichPush Push DeepLink Handling
529
+
530
+ /*----------------------------------------------------------------------------
531
+ storePendingDeeplink
532
+ * @param userInfo - NSDictionary
533
+ * Store the pending deeplink info in the static variable for later processing
534
+ -----------------------------------------------------------------------------*/
535
+ + (void)storePendingDeeplink:(NSDictionary *)userInfo {
536
+ @try {
537
+ // Store the pending deeplink info in the static variable for later processing
538
+ pendingDeeplink = userInfo;
539
+ RCTLog(@"Deeplink Push : storePendingDeeplink called" );
540
+ } @catch (NSException *exception) {
541
+ RCTLog(@"Deeplink Push : storePendingDeeplink exception %@",exception);
542
+ }
543
+ }
544
+
545
+ /*----------------------------------------------------------------------------
546
+ processPendingDeeplink
547
+ * Process the pending deeplink if it exists and the app is initialized
548
+ * Clear the pending deeplink after processing
549
+ -----------------------------------------------------------------------------*/
550
+ + (void)processPendingDeeplink {
551
+ @try {
552
+
553
+ RCTLog(@"Deeplink Push : processPendingDeeplink called isAppInitialized: %d , pendingDeeplink: %@",isAppInitialized,pendingDeeplink);
554
+ if (isAppInitialized && pendingDeeplink) {
555
+ RCTLog(@"Deeplink Push : handled in stored data");
556
+ [[appICE sharedInstance] handleClickOnPush:pendingDeeplink OpenDeepLink:YES];
557
+ pendingDeeplink = nil;
558
+ }
559
+ } @catch (NSException *exception) {
560
+ RCTLog(@"Deeplink Push : processPendingDeeplink exception %@",exception);
561
+ } @finally {
562
+ pendingDeeplink = nil;
563
+ RCTLog(@"Deeplink Push : finally processPendingDeeplink pendingDeeplink set as nil");
564
+ }
565
+
566
+ }
567
+
568
+ /*------------------------------------------------------
569
+ isDeviceReady
570
+ * @param isDeviceReady - BOOL
571
+ * Set the flag to indicate that the app is initialized
572
+ * Process any pending deeplinks after initialization
573
+ ------------------------------------------------------*/
574
+ RCT_EXPORT_METHOD(isDeviceReady: (BOOL)isActive)
575
+ {
576
+
577
+ RCTLog(@"Deeplink Push : isDeviceReady called state = %d",isActive );
578
+ if(isActive)
579
+ {
580
+ isAppInitialized = YES;
581
+ [AppIceReactPlugin processPendingDeeplink];
582
+ }
583
+ else
584
+ {
585
+ isAppInitialized = NO;
586
+ }
587
+ }
588
+
589
+ #pragma GETUSER WITH ARRAY
590
+
591
+ /*--------------------------------------------
592
+ * synchronizeData message True or False.
593
+ * @param timeout as int
594
+ * @callback will have the boolean
595
+ ---------------------------------------------*/
596
+ RCT_EXPORT_METHOD(synchronizeData:(int)timeout callback:(RCTResponseSenderBlock)callback)
597
+ {
598
+ // Save the callback for later use
599
+ RCTLog(@"GETUSER: synchronizeData");
600
+ [[appICE sharedInstance] synchronizeData:^(BOOL success) {
601
+ [self returnResult:@(success) withCallback:callback andError:nil];
602
+ }timeoutinSec:timeout];
603
+ }
604
+
605
+ /*--------------------------------------------
606
+ * getUserForIds with UserId
607
+ * userIds - NSArray
608
+ * @callback will have the boolean
609
+ ---------------------------------------------*/
610
+
611
+ RCT_EXPORT_METHOD(getUserForIds:(NSArray*)userIds callback:(RCTResponseSenderBlock)callback)
612
+ {
613
+ NSMutableArray *getUserArray =[[appICEUserDetails sharedUserDetails] getUser:userIds];
614
+ // Convert appICEUserDetails objects to dictionaries
615
+
616
+ NSMutableArray *formattedGetUser = [NSMutableArray array];
617
+ for (appICEUserDetails *getUserData in getUserArray) {
618
+ NSDictionary *formattedMessage = [getUserData toDictionary];
619
+ [formattedGetUser addObject:formattedMessage];
620
+ }
621
+ RCTLog(@"GETUSER: Formatted getUser Messages: %@", formattedGetUser);
622
+ [self returnResult:formattedGetUser withCallback:callback andError:nil];
623
+
624
+ }
625
+
626
+
627
+
628
+ - (void)returnResult:(id)result withCallback:(RCTResponseSenderBlock)callback andError:(NSString *)error {
629
+
630
+ if (callback == nil) {
631
+ RCTLog(@"AppICE:callback was nil");
632
+ return;
633
+ }
634
+ // id e = error != nil ? error : [NSNull null];
635
+ id r = result != nil ? result : [NSNull null];
636
+ RCTLog(@"AppICE: result: %@",r);
637
+ callback(@[r]);
638
+ }
639
+
640
+ @end
641
+