reactnative-plugin-appice 1.7.23 → 1.7.25

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