react-native-netmera 1.4.8 → 1.5.0-alpha01

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,52 +4,33 @@ NETMERA is a Mobile Application Engagement Platform. We offer a series of develo
4
4
 
5
5
  ## Installation
6
6
 
7
- `$ npm install react-native-netmera --save`
7
+ `yarn add react-native-netmera`
8
8
 
9
- ### Mostly automatic installation
9
+ or
10
10
 
11
- `$ react-native link react-native-netmera`
11
+ `npm install --save react-native-netmera`
12
12
 
13
- ### Manual installation
13
+ #### Link Netmera (for RN versions < 0.60)
14
14
 
15
+ Skip if using React Native version of 0.60 or greater.
15
16
 
16
- #### iOS
17
+ React Native: `react-native link react-native-netmera`
17
18
 
18
- 1. In XCode, in the project navigator, right click `Libraries` `Add Files to [your project's name]`
19
- 2. Go to `node_modules` ➜ `react-native-netmera` and add `RNNetmera.xcodeproj`
20
- 3. In XCode, in the project navigator, select your project. Add `libRNNetmera.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
21
- 4. Run your project (`Cmd+R`)
22
-
23
- #### Android
24
-
25
- 1. Open up `android/app/src/main/java/[...]/MainActivity.java`
26
- - Add `import com.netmera.reactnativesdk.RNNetmeraPackage;` to the imports at the top of the file
27
- - Add `new RNNetmeraPackage()` to the list returned by the `getPackages()` method
28
- 2. Append the following lines to `android/settings.gradle`:
29
- ```
30
- include ':react-native-netmera'
31
- project(':react-native-netmera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-netmera/android')
32
- ```
33
- 3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
34
- ```
35
- implementation project(':react-native-netmera')
36
- ```
37
-
38
- For both native sides(Android & iOS) you don't have to include extra Netmera SDK libraries.
19
+ For both native sides (Android & iOS) you don't have to include extra Netmera SDK libraries.
39
20
 
40
21
  ### Setup - Android Part
41
22
 
42
- 1) Create and register your app in [Firebase console](https://firebase.google.com/).
23
+ 1. Create and register your app in [Firebase console](https://firebase.google.com/).
43
24
 
44
- 2) Download `google-services.json` file and place it into android/app/ folder.
25
+ 2. Download `google-services.json` file and place it into android/app/ folder.
45
26
 
46
- 3) In your project's build gradle file, add the following dependency.
27
+ 3. In your project's build gradle file, add the following dependencies.
47
28
 
48
29
  ```
49
30
  buildscript {
50
31
  repositories {
51
32
  google()
52
- jcenter()
33
+ mavenCentral()
53
34
  maven {url 'https://developer.huawei.com/repo/'}
54
35
  }
55
36
 
@@ -63,7 +44,7 @@ buildscript {
63
44
  allprojects {
64
45
  repositories {
65
46
  google()
66
- jcenter()
47
+ mavenCentral()
67
48
  maven { url 'https://maven.google.com'}
68
49
  maven { url 'https://developer.huawei.com/repo/'}
69
50
  maven { url "https://release.netmera.com/release/android" }
@@ -71,46 +52,172 @@ allprojects {
71
52
  }
72
53
  ```
73
54
 
74
- 4) In your app's build gradle file, add the following dependency.
55
+ 4. In your app's build gradle file, add the following dependency.
75
56
 
76
57
  ```
77
58
 
78
59
  dependencies {
79
-
80
- implementation 'androidx.core:core:1.1.0'
81
-
60
+
61
+ implementation 'androidx.core:core:1.9.0'
62
+
82
63
  }
83
64
  ```
84
65
 
85
- 5) Add the following into the top of app's build.gradle file
66
+ 5. Add the following into the top of app's build.gradle file.
86
67
 
87
68
  ```
88
69
  apply plugin: 'com.google.gms.google-services'
89
70
  apply plugin: 'com.huawei.agconnect'
90
71
  ```
91
72
 
92
- 6) Create an application class as shown below.
73
+ 6. Create an application class as shown below.
93
74
 
94
75
  - Initialize Netmera SDK in your Application class.
95
76
 
96
- ```
77
+ ```
97
78
  public class MainApplication extends Application {
98
-
79
+
99
80
  @Override
100
81
  public void onCreate() {
101
82
  super.onCreate();
102
83
  RNNetmeraConfiguration netmeraConfiguration = new RNNetmeraConfiguration.Builder()
103
84
  .firebaseSenderId(<YOUR GCM SENDER ID>)
104
85
  .huaweiSenderId(<YOUR HMS SENDER ID>)
105
- .apiKey(<YOUR NETMERA API KEY>) // This is for enabling Netmera logs.
106
- .logging(true)
86
+ .apiKey(<YOUR NETMERA API KEY>)
87
+ .logging(true) // This is for enabling Netmera logs.
107
88
  .build(this);
108
89
  RNNetmera.initNetmera(netmeraConfiguration);
109
90
  }
110
91
  }
111
92
  ```
112
93
 
113
- 7) Create a new `NetmeraPushHeadlessTask.js` inside your React Native project.
94
+ ### Setup - iOS Part
95
+
96
+ 1. Navigate to ios folder in your terminal and run the following command.
97
+
98
+ ```
99
+ $ pod install
100
+ ```
101
+
102
+ 2. Download `GoogleService-Info.plist` file from Firebase and place it into ios/ folder.
103
+
104
+ 3. Enable push notifications for your project
105
+
106
+ 1. If you have not generated a valid push notification certificate yet,
107
+ generate one and then export by following the steps explained in [Configuring Push Notifications section of App Distribution Guide](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_certificate-based_connection_to_apns#2947597)
108
+ 2. Export the generated push certificate in .p12 format and upload to Netmera Dashboard.
109
+ 3. Enable Push Notifications capability for your application as explained in [Enable Push Notifications](https://developer.netmera.com/en/IOS/Quick-Start#enable-push-notifications) guide.
110
+ 4. Enable Remote notifications background mode for your application as explained in [Configuring Background Modes](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app#2980038) guide.
111
+
112
+ 4. If you want to use Android alike message sending from iOS to react native please consider shaping your AppDelegate class as following.
113
+
114
+ #### AppDelegate.h
115
+
116
+ ```
117
+ #import <React/RCTBridgeDelegate.h>
118
+ #import <UIKit/UIKit.h>
119
+ #import <Netmera/Netmera.h>
120
+ #import <NetmeraCore/NetmeraPushObject.h>
121
+ #import <UserNotifications/UserNotifications.h>
122
+
123
+ @interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate, NetmeraPushDelegate>
124
+
125
+ @property (nonatomic, strong) UIWindow *window;
126
+
127
+ @end
128
+ ```
129
+
130
+ #### AppDelegate.m
131
+
132
+ - Add the following to the top of AppDelegate.m file.
133
+
134
+ ```
135
+ #import <RNNetmera/RNNetmeraRCTEventEmitter.h>
136
+ #import <RNNetmera/RNNetmeraUtils.h>
137
+ #import <RNNetmera/RNNetmera.h>
138
+ ```
139
+
140
+ - Add the following lines into the `didFinishLaunchingWithOptions` method.
141
+
142
+ ```
143
+
144
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
145
+ {
146
+ // Add this line to set notification delegate
147
+ [UNUserNotificationCenter currentNotificationCenter].delegate = self;
148
+
149
+ ...
150
+
151
+ // Add these lines to init Netmera
152
+ [RNNetmera logging: YES]; // This is for enabling Netmera logs.
153
+ [RNNetmera initNetmera:[<YOUR NETMERA API KEY>]]; // Replace this with your own NETMERA API KEY.
154
+ [RNNetmera requestPushNotificationAuthorization];
155
+ [RNNetmera setPushDelegate:self];
156
+ [Netmera setAppGroupName:<YOUR APP GROUP NAME>]; // Set your app group name
157
+
158
+ return YES;
159
+ }
160
+ ```
161
+
162
+ - Add these methods to between `@implementation AppDelegate` and `@end`.
163
+
164
+ ```
165
+ @implementation AppDelegate
166
+
167
+ ...
168
+
169
+ // MARK: Push Delegate Methods
170
+
171
+ // Take push payload for Push clicked:
172
+ -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
173
+ {
174
+ if ([response.actionIdentifier isEqual:UNNotificationDismissActionIdentifier]) {
175
+ [RNNetmeraRCTEventEmitter onPushDismiss: @{@"userInfo" : response.notification.request.content.userInfo}];
176
+ } else if ([response.actionIdentifier isEqual:UNNotificationDefaultActionIdentifier]) {
177
+ [RNNetmeraRCTEventEmitter onPushOpen: @{@"userInfo" : response.notification.request.content.userInfo}];
178
+ }
179
+ completionHandler();
180
+ }
181
+
182
+ // Take push payload for push Received on application foreground:
183
+ -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
184
+ {
185
+ completionHandler(UNNotificationPresentationOptionAlert);
186
+ [RNNetmeraRCTEventEmitter onPushReceive: @{@"userInfo" : notification.request.content.userInfo}];
187
+ }
188
+
189
+ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
190
+ {
191
+ if(deviceToken == nil) {
192
+ return;
193
+ }
194
+ [RNNetmeraRCTEventEmitter onPushRegister: @{@"pushToken" : deviceToken}];
195
+ }
196
+
197
+ @end
198
+
199
+ ```
200
+
201
+ For example if you trigger `[RNNetmeraRCTEventEmitter onPushReceive: @{@"userInfo" : notification.request.content.userInfo}]` from AppDelegate, in the react native part the following method will be triggered.
202
+
203
+ ```
204
+ export const onPushReceive = async (message) => {
205
+ console.log("onPushReceive: ", message);
206
+ };
207
+ ```
208
+
209
+ 4. In order to use iOS10 Media Push, follow the instructions in [Netmera Product Hub.](https://developer.netmera.com/en/IOS/Push-Notifications#using-ios10-media-push) Differently, you should add the pods to the top of the `Podfile` as below.
210
+
211
+ ```
212
+ // For receiving Media Push, you must add Netmera pods to top of your Podfile.
213
+ pod "Netmera", "3.14.10-WithoutDependency"
214
+ pod "Netmera/NotificationServiceExtension", "3.14.10-WithoutDependency"
215
+ pod "Netmera/NotificationContentExtension", "3.14.10-WithoutDependency"
216
+ ```
217
+
218
+ ### Setup - React Native Part
219
+
220
+ 1. Create a new `NetmeraPushHeadlessTask.js` inside your React Native project.
114
221
 
115
222
  ```
116
223
  export const onPushRegister = async (message) => {
@@ -138,7 +245,7 @@ export const onCarouselObjectSelected = async (message) => {
138
245
  };
139
246
  ```
140
247
 
141
- 8) Init `NetmeraBroadcastReceiver` inside your `index.js` file.
248
+ 2. Init `NetmeraBroadcastReceiver` inside your `index.js` file.
142
249
 
143
250
  ```
144
251
  import {
@@ -158,28 +265,35 @@ Netmera.initBroadcastReceiver(
158
265
  onPushButtonClicked,
159
266
  onCarouselObjectSelected
160
267
  )
161
-
268
+
162
269
  // This should be called after Netmera.initBroadcastReceiver method.
163
270
  AppRegistry.registerComponent(appName, () => App);
164
271
  ```
165
272
 
166
- 9) If you have custom Firebase Messaging integration, please see usage below.
273
+ 3. If you have custom Firebase Messaging integration, please see usage below.
167
274
 
168
275
  ```
169
276
  messaging()
170
277
  .getToken(firebase.app().options.messagingSenderId)
171
278
  .then(pushToken => {
172
279
  Netmera.onNetmeraNewToken(pushToken)
173
- })
280
+ });
174
281
 
175
282
  messaging().onMessage(async remoteMessage => {
176
283
  if (Netmera.isNetmeraRemoteMessage(remoteMessage.data)) {
177
284
  Netmera.onNetmeraFirebasePushMessageReceived(remoteMessage.from, remoteMessage.data)
178
285
  }
179
286
  });
287
+
288
+ messaging().setBackgroundMessageHandler(async (remoteMessage) => {
289
+ if (Netmera.isNetmeraRemoteMessage(remoteMessage.data)) {
290
+ Netmera.onNetmeraFirebasePushMessageReceived(remoteMessage.from, remoteMessage.data)
291
+ }
292
+ });
293
+
180
294
  ```
181
295
 
182
- 10) If you have custom Huawei Messaging integration, please see usage below.
296
+ 4. If you have custom Huawei Messaging integration, please see usage below.
183
297
 
184
298
  ```
185
299
  HmsPushInstanceId.getToken("")
@@ -197,88 +311,12 @@ HmsPushEvent.onRemoteMessageReceived(event => {
197
311
  })
198
312
  ```
199
313
 
200
- ### Setup - iOS Part
201
-
202
- 1) Navigate to ios folder in your terminal and run the following command.
203
-
204
- ```
205
- $ pod install
206
- ```
207
-
208
- 2) If you want to use Android alike message sending from iOS to react native please consider shaping your AppDelegate class as following.
209
-
210
- ```
211
- #import "AppDelegate.h"
212
-
213
- #import <RNNetmera/RNNetmeraRCTEventEmitter.h>
214
- #import <RNNetmera/RNNetmera.h>
215
-
216
- @implementation AppDelegate
217
-
218
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
219
- {
220
-
221
- // Init Netmera
222
- [RNNetmera logging: YES];
223
- [RNNetmera initNetmera:[ReactNativeConfig envFor:@"NETMERA_API_KEY"]]; // Replace this with your own NETMERA API KEY.
224
- [RNNetmera requestPushNotificationAuthorization];
225
- [RNNetmera setPushDelegate:self];
226
- [Netmera setAppGroupName:@"group.com.netmerareactnativeexample"]; // Set your app group name
227
-
228
- return YES;
229
- }
230
-
231
- // Take push payload for Push clicked:
232
- -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
233
- {
234
- if ([response.actionIdentifier isEqual:UNNotificationDismissActionIdentifier]) {
235
- [RNNetmeraRCTEventEmitter onPushDismiss: @{@"userInfo" : response.notification.request.content.userInfo}];
236
- } else if ([response.actionIdentifier isEqual:UNNotificationDefaultActionIdentifier]) {
237
- [RNNetmeraRCTEventEmitter onPushOpen: @{@"userInfo" : response.notification.request.content.userInfo}];
238
- }
239
- completionHandler();
240
- }
241
-
242
- // Take push payload for push Received on application foreground:
243
- -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
244
- {
245
- completionHandler(UNNotificationPresentationOptionAlert);
246
- [RNNetmeraRCTEventEmitter onPushReceive: @{@"userInfo" : notification.request.content.userInfo}];
247
- }
248
-
249
- - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
250
- {
251
- if(deviceToken == nil) {
252
- return;
253
- }
254
- [RNNetmeraRCTEventEmitter onPushRegister: @{@"pushToken" : deviceToken}];
255
- }
256
-
257
- @end
258
-
259
- ```
260
- For example if you trigger `[RNNetmeraRCTEventEmitter onPushReceive: @{@"userInfo" : notification.request.content.userInfo}]` from AppDelegate, in the react native part the following method will be triggered.
261
- ```
262
- export const onPushReceive = async (message) => {
263
- console.log("onPushReceive: ", message);
264
- };
265
- ```
266
-
267
- 3) In order to use iOS10 Media Push, follow the instructions in [Netmera Product Hub.](https://developer.netmera.com/en/IOS/Push-Notifications#using-ios10-media-push)
268
-
269
- ```
270
- // For receiving Media Push, you must add Netmera pods to top of your Podfile
271
- pod "Netmera", "3.14.10-WithoutDependency"
272
- pod "Netmera/NotificationServiceExtension", "3.14.10-WithoutDependency"
273
- pod "Netmera/NotificationContentExtension", "3.14.10-WithoutDependency"
274
- ```
275
-
276
314
  ### Calling React Native methods
277
315
 
278
316
  ##### Update User Example
279
317
 
280
318
  ```
281
- updateUser() {
319
+ const updateUser = () => {
282
320
  const user = new NetmeraUser();
283
321
  user.userId = <userId>;
284
322
  user.name = <name>;
@@ -286,266 +324,84 @@ updateUser() {
286
324
  user.msisdn = <msisdn>;
287
325
  user.gender = <gender>;
288
326
  Netmera.updateUser(user)
289
- }
327
+ }
290
328
  ```
291
329
 
292
330
  ##### Sending Event Examples
293
331
 
332
+ You can send your events as follows. For more examples, please see the [example project](https://github.com/Netmera/Netmera-React-Native-Example/blob/master/src/Screens/Event.js).
333
+
294
334
  ```
295
- void sendLoginEvent() {
335
+ const sendLoginEvent = () => {
296
336
  const loginEvent = new LoginEvent();
297
337
  loginEvent.setUserId(<userId>);
298
338
  Netmera.sendEvent(loginEvent)
299
339
  }
300
340
 
301
- void sendRegisterEvent() {
341
+ const sendRegisterEvent = () => {
302
342
  const registerEvent = new RegisterEvent();
303
343
  Netmera.sendEvent(registerEvent)
304
344
  }
305
345
 
306
- void sendViewCartEvent() {
346
+ const sendViewCartEvent = () => {
307
347
  const viewCartEvent = new ViewCartEvent();
308
348
  viewCartEvent.subTotal = <subTotal>;
309
349
  viewCartEvent.itemCount = <itemCount>;
310
350
  Netmera.sendEvent(viewCartEvent)
311
351
  }
312
-
313
- void purchaseEvent() {
314
- const netmeraLineItem = new NetmeraLineItem();
315
- netmeraLineItem.setBrandId(<brandId>);
316
- netmeraLineItem.setBrandName(<brandName>);
317
- netmeraLineItem.setCampaignId(<campaignId>);
318
- netmeraLineItem.setCategoryIds(<categoryIds>);
319
- netmeraLineItem.setCategoryNames(<categoryNames>);
320
- netmeraLineItem.setKeywords(<keywords>);
321
- netmeraLineItem.setCount(<count>);
322
- netmeraLineItem.setId(<id>);
323
- netmeraLineItem.setPrice(<price>);
324
-
325
- const purchaseEvent = new CustomPurchaseEvent();
326
- purchaseEvent.coupon = <coupon>;
327
- purchaseEvent.discount = <discount>;
328
- purchaseEvent.grandTotal = <grandTotal>;
329
- purchaseEvent.itemCount = <itemCount>;
330
- purchaseEvent.paymentMethod = <paymentMethod>;
331
- purchaseEvent.subTotal = <subTotal>;
332
- purchaseEvent.shippingCost = <shippingCost>;
333
- purchaseEvent.purchaseLineItemEvent = [netmeraLineItem, netmeraLineItem];
334
- purchaseEvent.userName = <userName>;
335
- Netmera.sendEvent(purchaseEvent)
336
- }
337
352
  ```
338
- ##### Netmera Inbox Examples
339
353
 
340
- ```
341
- constructor() {
342
- super();
343
- this.state = {
344
- inbox: [],
345
- inboxState: Netmera.PUSH_OBJECT_STATUS_ALL,
346
- countForStatus: 0
347
- }
348
- }
354
+ ##### Push Notification Permissions
349
355
 
350
- fetchInbox = async () => {
351
- try {
352
- const netmeraInboxFilter = new NetmeraInboxFilter();
353
- netmeraInboxFilter.status = this.state.inboxState;
354
- netmeraInboxFilter.pageSize = 2;
355
- const inbox = await Netmera.fetchInbox(netmeraInboxFilter);
356
- console.log("inbox", inbox);
357
- this.setState({inbox: inbox});
358
- } catch (e) {
359
- console.log("error", e)
360
- }
361
- };
356
+ If you don't request notification permission at runtime, you can request it by calling the `requestPushNotificationAuthorization()` method.
357
+ Note: Notification runtime permissions are required on Android 13 (API 33) or higher.
358
+ Therefore, before calling the method, make sure your project targets an API of 33 and above.
362
359
 
363
- fetchNextPage = async () => {
364
- try {
365
- const inbox = await Netmera.fetchNextPage();
366
- this.setState({inbox: inbox});
367
- console.log("inbox", inbox)
368
- } catch (e) {
369
- console.log("error", e)
370
- }
371
- };
372
-
373
- updateAll = async () => {
374
- if (!this.state.inbox !== undefined) {
375
- let updateStatus = this.state.inboxState;
376
- if (updateStatus === Netmera.PUSH_OBJECT_STATUS_ALL) {
377
- Alert.alert("Error", "Please select different status than all!!")
378
- console.log("Please select different status than all!!");
379
- return;
380
- }
381
-
382
- try {
383
- Netmera.updateAll(this.state.inboxState).then(() => {
384
- this.fetchInbox();
385
- }).catch((error) => {
386
- console.log("error: " + error)
387
- })
388
- } catch (error) {
389
- console.log("error: " + error)
390
- }
391
- }
392
- };
393
-
394
- handlePushObject = async () => {
395
- if (this.state.inbox !== undefined && this.state.inbox.length > 0) {
396
- Netmera.handlePushObject(this.state.inbox[0].pushId)
397
- }
398
- };
360
+ ```
361
+ Netmera.requestPushNotificationAuthorization();
362
+ ```
399
363
 
400
- handleInteractiveAction = async () => {
401
- if (this.state.inbox !== undefined && this.state.inbox.length > 0) {
402
- for (let i = 0; i < this.state.inbox.length; i++) {
403
- const element = this.state.inbox[i];
404
- if (element.interactiveActions !== undefined && element.interactiveActions.length > 0) {
405
- const action = JSON.parse(element.interactiveActions)[0]
406
- Netmera.handleInteractiveAction(action.id);
407
- return;
408
- }
409
- }
410
- }
411
- };
364
+ You can call the `areNotificationsEnabled()` method if you need to know the status of permissions.
412
365
 
413
- countForStatus = async () => {
414
- try {
415
- const count = await Netmera.countForStatus(this.state.inboxState);
416
- this.setState({countForStatus: count})
417
- } catch (e) {
418
- }
419
- };
366
+ ```
367
+ await Netmera.areNotificationsEnabled() // Use the enabled status of permission as boolean
368
+ ```
420
369
 
421
- inboxUpdateStatus = async () => {
422
- if (this.state.inboxState === Netmera.PUSH_OBJECT_STATUS_ALL) {
423
- Alert.alert("Error", "Please select different status than all!!")
424
- console.log("Please select different status than all!!");
425
- return;
426
- }
427
- if (this.state.inbox === undefined || this.state.inbox < 2) {
428
- Alert.alert("Error", "Push objects count is less then 2!")
429
- console.log("Push objects count is less then 2!");
430
- return;
431
- }
432
- Netmera.inboxUpdateStatus(0, 2, this.state.inboxState).then(() => {
433
- console.log("2 push object status was changed successfully.")
434
- }).catch((error) => {
435
- console.log("error: " + error)
436
- });
437
- };
370
+ ##### Netmera Inbox Examples
438
371
 
439
- updateInboxState = (value) => {
440
- this.setState({inboxState: value})
441
- };
372
+ You can fetch the Netmera inbox as following. For more detailed usage, please see the [example project](https://github.com/Netmera/Netmera-React-Native-Example/blob/master/src/Screens/PushInbox.js).
442
373
 
443
- inboxCountForStatus = async () => {
374
+ ```
375
+ const fetchInbox = async () => {
444
376
  try {
445
- const filter = new NMInboxStatusCountFilter();
446
- filter.nmInboxStatus = this.state.inboxState;
447
- filter.includeExpired = true;
448
- const nmInboxStatusCount = await Netmera.getInboxCountForStatus(filter);
449
-
450
- let countStatusText = "ALL: " + nmInboxStatusCount[NMInboxStatus.STATUS_ALL] + ", " +
451
- "READ: " + nmInboxStatusCount[NMInboxStatus.STATUS_READ] + ", " +
452
- "UNREAD: " + nmInboxStatusCount[NMInboxStatus.STATUS_UNREAD] + ", " +
453
- "DELETED: " + nmInboxStatusCount[NMInboxStatus.STATUS_DELETED]
454
-
455
- this.setState({countForStatus: countStatusText})
456
- console.log("nmInboxStatusCount: ", countStatusText);
377
+ const netmeraInboxFilter = new NetmeraInboxFilter();
378
+ netmeraInboxFilter.status = Netmera.PUSH_OBJECT_STATUS_UNREAD;
379
+ netmeraInboxFilter.pageSize = 2; // Fetch two push object
380
+ const inbox = await Netmera.fetchInbox(netmeraInboxFilter);
381
+ console.log("inbox", inbox);
457
382
  } catch (e) {
458
383
  console.log("error", e)
459
384
  }
460
- };
385
+ }
461
386
  ```
462
387
 
463
388
  ##### Netmera Inbox Category Examples
464
389
 
465
- ```
466
- constructor() {
467
- super();
468
- this.state = {
469
- categories: [],
470
- userCategoryPreferences: [],
471
- categoryState: Netmera.PUSH_OBJECT_STATUS_ALL,
472
- }
473
- }
390
+ You can fetch the Netmera category as following. For more detailed usage, please see the [example project](https://github.com/Netmera/Netmera-React-Native-Example/blob/master/src/Screens/Category.js).
474
391
 
475
- fetchCategory = async () => {
392
+ ```
393
+ const fetchCategory = async () => {
476
394
  try {
477
- const netmeraCategoryFilter = new NetmeraCategoryFilter();
478
- netmeraCategoryFilter.status = this.state.categoryState;
479
- netmeraCategoryFilter.pageSize = 1;
480
- const categories = await Netmera.fetchCategory(netmeraCategoryFilter);
395
+ const netmeraCategoryFilter = new NetmeraCategoryFilter()
396
+ netmeraCategoryFilter.status = categoryState
397
+ netmeraCategoryFilter.pageSize = 1 // Fetch one by one
398
+ const categories = await Netmera.fetchCategory(netmeraCategoryFilter)
481
399
  console.log("categories", categories);
482
- this.setState({categories: categories});
483
- } catch (e) {
484
- console.log("error", e)
485
- }
486
- };
487
-
488
- fetchNextCategoryPage = async () => {
489
- try {
490
- const categories = await Netmera.fetchNextCategoryPage();
491
- this.setState({categories: categories});
492
- console.log("categories", categories)
400
+ setCategories(categories)
493
401
  } catch (e) {
494
402
  console.log("error", e)
495
403
  }
496
404
  };
497
-
498
- handlePushObject = async () => {
499
- if (this.state.categories !== undefined && this.state.categories.length > 0) {
500
- Netmera.handleLastMessage(this.state.categories[0].categoryName)
501
- }
502
- };
503
-
504
- updateStatusCategories = async () => {
505
- if (this.state.categoryState === Netmera.PUSH_OBJECT_STATUS_ALL) {
506
- Alert.alert("Error", "Please select different status than all!!")
507
- console.log("Please select different status than all!!");
508
- return;
509
- }
510
- if (this.state.categories === undefined || this.state.categories < 1) {
511
- Alert.alert("Error", "Category object not found!")
512
- console.log("Category object not found!");
513
- return;
514
- }
515
-
516
- const count = this.state.categories.length < 3 ? this.state.categories.length : 2;
517
-
518
- Netmera.updateStatusByCategories(0, count, this.state.categoryState).then(() => {
519
- console.log("Category object status was changed successfully.")
520
- }).catch((error) => {
521
- console.log("error: " + error)
522
- });
523
- };
524
-
525
- updateCategoryState = (value) => {
526
- this.setState({categoryState: value})
527
- };
528
-
529
- getUserCategoryPreferenceList = async () => {
530
- Netmera.getUserCategoryPreferenceList().then((response) => {
531
- this.setState({categories: response})
532
- console.log("User Category Preference List: " + response)
533
- }).catch((error) => {
534
- console.log("error: " + error)
535
- });
536
- };
537
-
538
- setUserCategoryPreference = async (item) => {
539
- Netmera.setUserCategoryPreference(item.categoryId, !item.optInStatus).then(() => {
540
- console.log("Successfully set user category preference list")
541
- setTimeout(() => {
542
- this.getUserCategoryPreferenceList()
543
- }, 500)
544
-
545
- }).catch((error) => {
546
- console.log("error: " + error)
547
- });
548
- };
549
405
  ```
550
406
 
551
407
  ##### Netmera Getting ExternalId (if exists before)
@@ -554,4 +410,13 @@ updateUser() {
554
410
  Netmera.currentExternalId()
555
411
  ```
556
412
 
557
- Please explore example folder in the Netmera SDK library for detailed information.
413
+ ##### Netmera Popup Presentation
414
+
415
+ To enable popup presentation, you need to call the `enablePopupPresentation()` method on the page where you want to display the popup.
416
+ Note: To show popup on the app start or everywhere in the app, please add this to `index.js` file.
417
+
418
+ ```
419
+ Netmera.enablePopupPresentation();
420
+ ```
421
+
422
+ Please explore [our example project](https://github.com/Netmera/Netmera-React-Native-Example) for detailed information.