reactnative-plugin-appice 1.6.1 → 1.6.3

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.
@@ -347,6 +347,45 @@ public class AppIceReactPluginModule extends ReactContextBaseJavaModule {
347
347
  ContextSdk.pushNotificationClicked(payload, ctx);
348
348
  }
349
349
 
350
+
351
+
352
+ //===========================================
353
+ // Device Setting
354
+ //===========================================
355
+
356
+ /**
357
+ * To set the custom device_id.
358
+ */
359
+ @ReactMethod
360
+ public void setInternalId(String deviceId){
361
+ //TODO{ we can not call setDevice Id here because it
362
+ // will directly call start context with new device id
363
+ // but here we want to store the data only
364
+ // }
365
+ //ContextSdk.setInternalId();
366
+ }
367
+
368
+ /**
369
+ * To get the ad_id from sdk.
370
+ *
371
+ * @callback will have the string
372
+ */
373
+ @ReactMethod
374
+ public void getDeviceId(Callback callback){
375
+ Context context = getReactApplicationContext();
376
+ callback.invoke(ContextSdk.getInternalId(context));
377
+ }
378
+ /**
379
+ * To get the user_id from sdk.
380
+ *
381
+ * @callback will have the string
382
+ */
383
+ @ReactMethod
384
+ public void getUserId(Callback callback){
385
+ Context context = getReactApplicationContext();
386
+ callback.invoke(ContextSdk.getUserId(context));
387
+ }
388
+
350
389
  public static void sendEvent(String eventName, @Nullable WritableMap params) {
351
390
  try {
352
391
  context.
package/example/App.js CHANGED
@@ -83,6 +83,12 @@ addAppICEAPIListeners();
83
83
  color="#841584"
84
84
 
85
85
  />
86
+ <Button
87
+ onPress={getUserId}
88
+ title="getUserId"
89
+ color="#841584"
90
+
91
+ />
86
92
  </View>
87
93
  )
88
94
 
@@ -143,6 +149,12 @@ const setLanguage = () => {
143
149
  };
144
150
  const sendView = () => {
145
151
  AppICE.tagEvent("HomeScreen", {});
146
- }
152
+ };
153
+
154
+ const getUserId = () => {
155
+ AppICE.getUserId((userIds: any[]) => {
156
+ console.log('User IDs:', userIds);
157
+ });
158
+ };
147
159
 
148
160
  export default HelloWorldApp;
@@ -16,7 +16,7 @@
16
16
  "install": "^0.13.0",
17
17
  "react": "18.0.0",
18
18
  "react-native": "0.69.4",
19
- "reactnative-plugin-appice": "^1.6.1"
19
+ "reactnative-plugin-appice": "^1.6.3"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@babel/core": "^7.12.9",
package/index.js CHANGED
@@ -3,6 +3,7 @@ import { Platform, Component } from 'react-native';
3
3
 
4
4
  const AppIceReactPlugin = NativeModules.AppIceReactPlugin;
5
5
  var eventEmitter;
6
+
6
7
  if(Platform.OS === 'ios')
7
8
  {
8
9
  eventEmitter = NativeModules.AppICEReactEvent ? new NativeEventEmitter(NativeModules.AppICEReactEvent) : DeviceEventEmitter;
@@ -58,10 +59,20 @@ var AppICEReact = {
58
59
  * @param {string} region - e.i. US/GCC/IND
59
60
  * @param {string} baseUrl -
60
61
  * @param {object} certs - arrays of certificate paths
61
- * keys are strings and values can be string, number or boolean.
62
+ * startContext executes after getDeviceId callback
63
+ * if res exist assign the value of res else assign deviceID
62
64
  */
63
65
  startContext: function (appID, appKey, apiKey, deviceID, region, baseUrl, certs){
64
- AppIceReactPlugin.startContext(appID, appKey, apiKey, deviceID, region, baseUrl, certs)
66
+ this.getDeviceId(( res ) =>
67
+ {
68
+ if(res){
69
+ console.log('Res variable'+res);
70
+ AppIceReactPlugin.startContext(appID, appKey, apiKey, res, region, baseUrl, certs)
71
+ }else{
72
+ console.log('deviceID variable'+deviceID);
73
+ AppIceReactPlugin.startContext(appID, appKey, apiKey, deviceID, region, baseUrl, certs)
74
+ }
75
+ });
65
76
  },
66
77
 
67
78
  /**
@@ -101,6 +112,10 @@ var AppICEReact = {
101
112
  AppIceReactPlugin.setUser(profile);
102
113
  },
103
114
 
115
+ //===============================================
116
+ // User id setting
117
+ //===============================================
118
+
104
119
  /**
105
120
  * Set unique user id
106
121
  * @param {object} values - array of userids
@@ -109,6 +124,14 @@ var AppICEReact = {
109
124
  AppIceReactPlugin.setUserId(values);
110
125
  },
111
126
 
127
+ /**
128
+ * Getuser id
129
+ * @param {object} values - array of userids
130
+ */
131
+ getUserId: function(callback){
132
+ callWithCallback ('getUserId', null, callback);
133
+ },
134
+
112
135
  getCustomDataFromPayload: function (object) {
113
136
  let userObj = JSON.parse(object, (key, value) => {
114
137
  return value;
@@ -118,7 +141,53 @@ var AppICEReact = {
118
141
 
119
142
  return map;
120
143
  },
144
+
145
+ /**
146
+ * call this function before clearing old data from db/keychain
147
+ */
148
+ preInitialise: function(){
149
+
150
+ this.getDeviceId(( res ) =>
151
+ {
152
+
153
+ if(res){
154
+ console.log('setInternalId');
155
+ this.setInternalId(res);
156
+ }
157
+ });
158
+ },
159
+
160
+ //===============================================
161
+ // Device id setting
162
+ //===============================================
163
+
164
+ getDeviceId: function(callback){
165
+ callWithCallback ('getDeviceId', null, callback)
166
+
167
+ },
168
+
169
+ setInternalId: function (deviceId){
170
+ AppIceReactPlugin.setInternalId(deviceId);
171
+ },
172
+
121
173
  };
122
174
 
175
+ // internal function for callback
176
+ function callWithCallback(method, args, callback) {
177
+ if (typeof callback === 'undefined' || callback == null || typeof callback !== 'function') {
178
+ callback = (err, res) => {
179
+ defaultCallback(method, err, res);
180
+ };
181
+ }
182
+
183
+ if (args == null) {
184
+ args = [];
185
+ }
186
+
187
+ args.push(callback);
188
+
189
+ AppIceReactPlugin[method].apply(this, args);
190
+ }
191
+
123
192
 
124
193
  module.exports = AppICEReact;
@@ -102,6 +102,29 @@ RCT_EXPORT_METHOD(setUserId:(NSArray*)userIdArray)
102
102
  [[appICE sharedInstance] setUserId:userIdArray];
103
103
  }
104
104
 
105
+ /**
106
+ * Call the native method to getUserId
107
+ * Check if the getUserIdArray is not nil and the callback function is provided
108
+ * else Handle the case when getUserIdArray is nil
109
+ * Invoke the callback with an array containing NSNull to represent nil
110
+ */
111
+
112
+ RCT_EXPORT_METHOD(getUserId:(RCTResponseSenderBlock)callback)
113
+ {
114
+
115
+ NSMutableArray *getUserIdArray = [[appICE sharedInstance] getUserId];
116
+ RCTLog(@"getUserIdArray %@", getUserIdArray);
117
+
118
+ if (getUserIdArray && getUserIdArray.count > 0 && callback) {
119
+ callback(@[getUserIdArray]);
120
+ } else {
121
+ if (callback) {
122
+ callback(@[[NSNull null]]);
123
+ }
124
+ }
125
+
126
+ }
127
+
105
128
  RCT_EXPORT_METHOD(pushNotificationClicked:(NSDictionary*)userInfo)
106
129
  {
107
130
  [[appICE sharedInstance] pushNotificationClickedEvent:userInfo];
@@ -185,6 +208,30 @@ RCT_EXPORT_METHOD(inAppClicked:(NSDictionary*)userInfo)
185
208
  }];
186
209
 
187
210
  }
211
+ RCT_EXPORT_METHOD(setInternalId:(NSString*) internalId)
212
+ {
213
+ [[appICE sharedInstance] setInternalId:internalId];
214
+ }
215
+
216
+ /**
217
+ * Call the native method to getDeviceId
218
+ * Check if the internal ID is not nil and the callback function is provided
219
+ * else Handle the case when getDeviceId is nil
220
+ * Invoke the callback with an array containing NSNull to represent nil
221
+ */
222
+ RCT_EXPORT_METHOD(getDeviceId:(RCTResponseSenderBlock)callback)
223
+ {
224
+ NSString *getinternalId = [[appICE sharedInstance] getInternalId];
225
+ RCTLog(@"getinternalID %@", getinternalId);
226
+
227
+ if (getinternalId != nil && callback) {
228
+ callback(@[getinternalId]);
229
+ } else {
230
+ if (callback) {
231
+ callback(@[[NSNull null]]);
232
+ }
233
+ }
234
+ }
188
235
 
189
236
  @end
190
237
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactnative-plugin-appice",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "appICE React Native SDK",
5
5
  "main": "index.js",
6
6
  "files": [