react-native-netmera 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.
package/README.md CHANGED
@@ -215,6 +215,19 @@ export const onPushReceive = async (message) => {
215
215
  pod "Netmera/NotificationContentExtension", "3.14.10-WithoutDependency"
216
216
  ```
217
217
 
218
+ 5. In order to use the widget URL callback, add these methods to between `@implementation AppDelegate` and `@end`.
219
+
220
+ ```
221
+ // Required code block to handle widget URL's in React Native
222
+ - (BOOL)shouldHandleOpenURL:(NSURL *)url forPushObject:(NetmeraPushObject *)object {
223
+ return NO;
224
+ }
225
+
226
+ - (void)handleOpenURL:(NSURL *)url forPushObject:(NetmeraPushObject *)object {
227
+ [RNNetmeraRCTEventEmitter handleOpenURL:url forPushObject:object];
228
+ }
229
+ ```
230
+
218
231
  ### Setup - React Native Part
219
232
 
220
233
  1. Create a new `NetmeraPushHeadlessTask.ts` inside your React Native project.
@@ -351,6 +364,16 @@ You can send your events as follows. For more examples, please see the [example
351
364
  }
352
365
  ```
353
366
 
367
+ ##### Widget URL Callback
368
+
369
+ In order to use the widget URL callback, use `onWidgetUrlTriggered` method as follows.
370
+
371
+ ```
372
+ Netmera.onWidgetUrlTriggered(url => {
373
+ console.log('Netmera triggered widget url: ', url);
374
+ });
375
+ ```
376
+
354
377
  ##### Push Notification Permissions
355
378
 
356
379
  If you don't request notification permission at runtime, you can request it by calling the `requestPushNotificationAuthorization()` method.
package/RNNetmera.podspec CHANGED
@@ -18,6 +18,6 @@ Pod::Spec.new do |s|
18
18
  s.requires_arc = true
19
19
 
20
20
  s.dependency 'React'
21
- s.dependency 'Netmera','3.16.0-WithoutDependency3'
21
+ s.dependency 'Netmera','3.22.0-WithoutDependency'
22
22
  end
23
23
 
@@ -7,6 +7,7 @@
7
7
  <option name="testRunner" value="GRADLE" />
8
8
  <option name="distributionType" value="DEFAULT_WRAPPED" />
9
9
  <option name="externalProjectPath" value="$PROJECT_DIR$" />
10
+ <option name="gradleJvm" value="jbr-17" />
10
11
  </GradleProjectSettings>
11
12
  </option>
12
13
  </component>
@@ -1,4 +1,3 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
1
  <project version="4">
3
2
  <component name="ProjectRootManager" version="2" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
4
3
  <output url="file://$PROJECT_DIR$/build/classes" />
@@ -15,8 +15,8 @@ android {
15
15
  }
16
16
 
17
17
  dependencies {
18
- implementation 'com.netmera:nmcore:3.10.2'
19
- implementation 'com.netmera:nmfcm:3.10.2'
20
- implementation 'com.netmera:nmhms:3.10.1'
18
+ implementation 'com.netmera:nmcore:3.11.3'
19
+ implementation 'com.netmera:nmfcm:3.11.0'
20
+ implementation 'com.netmera:nmhms:3.11.0'
21
21
  implementation 'com.facebook.react:react-native:+'
22
22
  }
@@ -23,7 +23,7 @@ public class RNNetmera {
23
23
  static void setNetmeraHeaders() {
24
24
  ContentValues headerValues = new ContentValues();
25
25
  headerValues.put("X-netmera-framework", "react");
26
- headerValues.put("X-netmera-frameworkV", "1.6.1");
26
+ headerValues.put("X-netmera-frameworkV", "1.6.3");
27
27
  Netmera.setNetmeraHeaders(headerValues);
28
28
  }
29
29
 
@@ -2,15 +2,16 @@ package com.netmera.reactnativesdk;
2
2
 
3
3
  import android.content.Context;
4
4
 
5
- import com.google.firebase.FirebaseApp;
6
5
  import com.netmera.NetmeraConfiguration;
7
6
  import com.netmera.callbacks.NMInAppMessageActionCallbacks;
8
7
  import com.netmera.callbacks.NMPushActionCallbacks;
8
+ import com.netmera.callbacks.NMWebWidgetCallbacks;
9
9
 
10
10
  public class RNNetmeraConfiguration {
11
11
 
12
12
  NMInAppMessageActionCallbacks nmInAppMessageActionCallbacks;
13
13
  NMPushActionCallbacks nmPushActionCallbacks;
14
+ NMWebWidgetCallbacks nmWebWidgetCallbacks;
14
15
  Context context;
15
16
  String baseUrl;
16
17
  String huaweiSenderId;
@@ -20,6 +21,7 @@ public class RNNetmeraConfiguration {
20
21
 
21
22
  private RNNetmeraConfiguration(Builder builder) {
22
23
  this.nmInAppMessageActionCallbacks = builder.nmInAppMessageActionCallbacks;
24
+ this.nmWebWidgetCallbacks = builder.nmWebWidgetCallbacks;
23
25
  this.nmPushActionCallbacks = builder.nmPushActionCallbacks;
24
26
  this.context = builder.context;
25
27
  this.baseUrl = builder.baseUrl;
@@ -35,6 +37,11 @@ public class RNNetmeraConfiguration {
35
37
  this.nmPushActionCallbacks :
36
38
  new RNNetmeraPushBroadcastReceiver();
37
39
 
40
+ NMWebWidgetCallbacks nmWebWidgetCallbacks =
41
+ this.nmWebWidgetCallbacks != null ?
42
+ this.nmWebWidgetCallbacks :
43
+ new RNNetmeraWebWidgetCallbacks();
44
+
38
45
  NetmeraConfiguration.Builder builder = new NetmeraConfiguration.Builder();
39
46
 
40
47
  if (firebaseSenderId != null) {
@@ -60,12 +67,14 @@ public class RNNetmeraConfiguration {
60
67
  return builder.logging(logging)
61
68
  .disableSerializeRule(true)
62
69
  .nmPushActionCallbacks(nmPushActionCallbacks)
70
+ .nmWebWidgetCallbacks(nmWebWidgetCallbacks)
63
71
  .build(context);
64
72
  }
65
73
 
66
74
  public static class Builder {
67
75
  private NMInAppMessageActionCallbacks nmInAppMessageActionCallbacks;
68
76
  private NMPushActionCallbacks nmPushActionCallbacks;
77
+ private NMWebWidgetCallbacks nmWebWidgetCallbacks;
69
78
  private Context context;
70
79
  private String baseUrl;
71
80
  private String huaweiSenderId;
@@ -83,6 +92,11 @@ public class RNNetmeraConfiguration {
83
92
  return this;
84
93
  }
85
94
 
95
+ public Builder nmWebWidgetCallbacks(NMWebWidgetCallbacks nmWebWidgetCallbacks) {
96
+ this.nmWebWidgetCallbacks = nmWebWidgetCallbacks;
97
+ return this;
98
+ }
99
+
86
100
  public Builder baseUrl(String baseUrl) {
87
101
  this.baseUrl = baseUrl;
88
102
  return this;
@@ -1,8 +1,7 @@
1
1
  //
2
2
  // RNNetmeraModule.java
3
- // Netmera SDK
4
3
  //
5
- // Created by Huseyin Kocoglu on 22.04.2019.
4
+ // Created by Initial Code
6
5
  // Copyright © 2019 Netmera. All rights reserved.
7
6
  //
8
7
 
@@ -18,6 +17,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
18
17
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
19
18
  import com.facebook.react.bridge.ReactMethod;
20
19
  import com.facebook.react.bridge.ReadableMap;
20
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
21
21
  import com.netmera.Netmera;
22
22
  import com.netmera.NetmeraCategory;
23
23
  import com.netmera.NetmeraError;
@@ -28,8 +28,10 @@ import com.netmera.NetmeraInteractiveAction;
28
28
  import com.netmera.NetmeraPushObject;
29
29
  import com.netmera.callbacks.NMCategoryPreferenceFetchCallback;
30
30
  import com.netmera.callbacks.NMCategoryPreferenceSetCallback;
31
+ import com.netmera.callbacks.NMFetchCouponsResultListener;
31
32
  import com.netmera.callbacks.NMInboxCountResultListener;
32
33
  import com.netmera.data.NMCategoryPreference;
34
+ import com.netmera.data.NMCouponDetail;
33
35
  import com.netmera.data.NMInboxStatusCount;
34
36
  import com.netmera.data.NMInboxStatusCountFilter;
35
37
 
@@ -66,6 +68,8 @@ public class RNNetmeraModule extends ReactContextBaseJavaModule {
66
68
  private static final String ERROR_MESSAGE_CATEGORY_PREFERENCE = "Error occurred while fetching user category preference list.";
67
69
  private static final String ERROR_CODE_SET_CATEGORY_PREFERENCE = "2025";
68
70
  private static final String ERROR_MESSAGE_SET_CATEGORY_PREFERENCE = "Error occurred while setting user category preference list.";
71
+ private static final String ERROR_CODE_COUPON_FETCH = "2026";
72
+ private static final String ERROR_MESSAGE_COUPON_FETCH = "Error occurred while fetching coupons.";
69
73
 
70
74
  public static ReactApplicationContext reactContext;
71
75
  private NetmeraInbox netmeraInbox;
@@ -142,6 +146,22 @@ public class RNNetmeraModule extends ReactContextBaseJavaModule {
142
146
  Netmera.turnOffSendingEventAndUserUpdate(turnOff);
143
147
  }
144
148
 
149
+ @ReactMethod
150
+ public void fetchCoupons(final int page, final int max, final Promise promise) {
151
+ Netmera.fetchCoupons(page, max, new NMFetchCouponsResultListener() {
152
+
153
+ @Override
154
+ public void onSuccess(@Nullable List<NMCouponDetail> list) {
155
+ promise.resolve(RNNetmeraUtil.mapCouponObjects(list));
156
+ }
157
+
158
+ @Override
159
+ public void onFailure(@Nullable String s) {
160
+ promise.reject(ERROR_CODE_COUPON_FETCH, ERROR_MESSAGE_COUPON_FETCH);
161
+ }
162
+ });
163
+ }
164
+
145
165
  @ReactMethod
146
166
  public void fetchInbox(ReadableMap readableMap, final Promise promise) {
147
167
  NetmeraInboxFilter.Builder builder = new NetmeraInboxFilter.Builder();
@@ -529,4 +549,8 @@ public class RNNetmeraModule extends ReactContextBaseJavaModule {
529
549
  private boolean hasKey(ReadableMap map, String key) {
530
550
  return map.hasKey(key) && !map.isNull(key);
531
551
  }
552
+
553
+ public static void emitEvent(String eventName, String eventData) {
554
+ reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, eventData);
555
+ }
532
556
  }
@@ -26,6 +26,7 @@ import com.netmera.NetmeraCarouselObject;
26
26
  import com.netmera.NetmeraPushObject;
27
27
  import com.netmera.NetmeraPushStyle;
28
28
  import com.netmera.data.NMCategoryPreference;
29
+ import com.netmera.data.NMCouponDetail;
29
30
  import com.netmera.data.NMInboxStatus;
30
31
  import com.netmera.data.NMInboxStatusCount;
31
32
 
@@ -191,6 +192,34 @@ class RNNetmeraUtil {
191
192
  return array;
192
193
  }
193
194
 
195
+ public static WritableArray mapCouponObjects(List<NMCouponDetail> couponObjects) {
196
+ WritableArray couponObjectList = Arguments.createArray();
197
+ for (NMCouponDetail netmeraCouponObject : couponObjects) {
198
+ couponObjectList.pushMap(mapCouponObject(netmeraCouponObject));
199
+ }
200
+ return couponObjectList;
201
+ }
202
+
203
+ public static WritableMap mapCouponObject(NMCouponDetail couponObject) {
204
+ WritableMap couponObjectMap = Arguments.createMap();
205
+ if (couponObject == null) {
206
+ return couponObjectMap;
207
+ }
208
+ couponObjectMap.putString("couponId", couponObject.getCouponId());
209
+ couponObjectMap.putString("name", couponObject.getName());
210
+ couponObjectMap.putString("code", couponObject.getCode());
211
+
212
+ if (couponObject.getAssignDate() != null) {
213
+ couponObjectMap.putString("assignDate", couponObject.getAssignDate().toString());
214
+ }
215
+
216
+ if (couponObject.getExpireDate() != null) {
217
+ couponObjectMap.putString("expireDate", couponObject.getExpireDate().toString());
218
+ }
219
+
220
+ return couponObjectMap;
221
+ }
222
+
194
223
  public static WritableArray mapPushObjects(List<NetmeraPushObject> pushObjects) {
195
224
  WritableArray pushObjectList = Arguments.createArray();
196
225
  for (NetmeraPushObject netmeraPushObject : pushObjects) {
@@ -0,0 +1,27 @@
1
+ package com.netmera.reactnativesdk;
2
+
3
+ import com.netmera.callbacks.NMWebWidgetCallbacks;
4
+
5
+ public class RNNetmeraWebWidgetCallbacks implements NMWebWidgetCallbacks {
6
+ private static final String ON_WIDGET_URL_TRIGGERED = "onWidgetUrlTriggered";
7
+
8
+ @Override
9
+ public void onDeeplinkTriggered(String s) {
10
+ RNNetmeraModule.emitEvent(ON_WIDGET_URL_TRIGGERED, s);
11
+ }
12
+
13
+ @Override
14
+ public void onOpenUrlTriggered(String s) {
15
+ RNNetmeraModule.emitEvent(ON_WIDGET_URL_TRIGGERED, s);
16
+ }
17
+
18
+ @Override
19
+ public void onWebWidgetShown(String s) {
20
+ // There is no equivalent for this feature in iOS
21
+ }
22
+
23
+ @Override
24
+ public void onWebWidgetDismiss(String s) {
25
+ // There is no equivalent for this feature in iOS
26
+ }
27
+ }
package/ios/RNNetmera.m CHANGED
@@ -31,6 +31,8 @@ NSString *const ERROR_CODE_GET_CATEGORY_PREFERENCE = @"2024";
31
31
  NSString *const ERROR_MESSAGE_GET_CATEGORY_PREFERENCE = @"Error occurred while fetching user category preference list.";
32
32
  NSString *const ERROR_CODE_SET_CATEGORY_PREFERENCE = @"2025";
33
33
  NSString *const ERROR_MESSAGE_SET_CATEGORY_PREFERENCE = @"Error occurred while setting user category preference list.";
34
+ NSString *const ERROR_CODE_COUPON_FETCH = @"2026";
35
+ NSString *const ERROR_MESSAGE_COUPON_FETCH = @"Error occurred while fetching coupons.";
34
36
 
35
37
  @implementation RNNetmera
36
38
 
@@ -46,7 +48,7 @@ NSString *const ERROR_MESSAGE_SET_CATEGORY_PREFERENCE = @"Error occurred while s
46
48
 
47
49
  + (void)setNetmeraHeaders {
48
50
  [Netmera setFramework:@"react"];
49
- [Netmera setFrameworkVersion:@"1.6.1"];
51
+ [Netmera setFrameworkVersion:@"1.6.3"];
50
52
  }
51
53
 
52
54
  + (void)setPushDelegate:(NSObject<NetmeraPushDelegate> *)delegate {
@@ -131,6 +133,28 @@ RCT_EXPORT_METHOD(stopDataTransfer) {
131
133
  [Netmera stopDataTransfer];
132
134
  }
133
135
 
136
+ RCT_EXPORT_METHOD(fetchCoupons:(int)page
137
+ max: (int)max
138
+ resolver: (RCTPromiseResolveBlock)resolve
139
+ rejecter:(RCTPromiseRejectBlock)reject) {
140
+ NetmeraCouponFilter *filter = [[NetmeraCouponFilter alloc] init];
141
+
142
+ filter.page = page;
143
+ filter.max = max;
144
+
145
+ [Netmera fetchCouponUsingFilter:filter completion:^(NSArray<NetmeraCouponObject *> *coupons, NSError *error) {
146
+ if (error) {
147
+ reject(ERROR_CODE_COUPON_FETCH, ERROR_MESSAGE_COUPON_FETCH, nil);
148
+ } else {
149
+ NSMutableArray *array = [[NSMutableArray alloc]init];
150
+ for(NetmeraCouponObject *object in coupons){
151
+ [array addObject:[[RNNetmeraUtils shared] dictionaryFromCouponObject:object]];
152
+ }
153
+ resolve(array);
154
+ }
155
+ }];
156
+ }
157
+
134
158
  RCT_EXPORT_METHOD(fetchInbox:(NSDictionary *)inboxDictionary
135
159
  resolver: (RCTPromiseResolveBlock)resolve
136
160
  rejecter:(RCTPromiseRejectBlock)reject) {
@@ -1,13 +1,13 @@
1
1
  //
2
2
  // RNNetmeraRCTEventEmitter.h
3
- // Netmera SDK
4
3
  //
5
- // Created by Huseyin Kocoglu on 22.04.2019.
4
+ // Created by Initial Code
6
5
  // Copyright © 2019 Netmera. All rights reserved.
7
6
  //
8
7
 
9
8
  #import <React/RCTBridgeModule.h>
10
9
  #import <React/RCTEventEmitter.h>
10
+ #import <Netmera/Netmera.h>
11
11
 
12
12
  @interface RNNetmeraRCTEventEmitter : RCTEventEmitter <RCTBridgeModule>
13
13
 
@@ -15,6 +15,7 @@
15
15
  +(void) onPushReceive:(NSDictionary*)dict;
16
16
  +(void) onPushDismiss:(NSDictionary*)dict;
17
17
  +(void) onPushOpen:(NSDictionary *)dict;
18
+ +(void) handleOpenURL:(NSURL *)url forPushObject:(NetmeraPushObject *)object;
18
19
 
19
20
  @end
20
21
 
@@ -1,8 +1,7 @@
1
1
  //
2
2
  // RNNetmeraRCTEventEmitter.m
3
- // Netmera SDK
4
3
  //
5
- // Created by Huseyin Kocoglu on 22.04.2019.
4
+ // Created by Initial Code
6
5
  // Copyright © 2019 Netmera. All rights reserved.
7
6
  //
8
7
 
@@ -46,7 +45,7 @@ NSDictionary* waitingOnPushDismiss = nil;
46
45
 
47
46
  - (NSArray<NSString *> *)supportedEvents
48
47
  {
49
- return @[@"onPushReceive", @"onPushOpen", @"onPushRegister", @"onPushDismiss"];
48
+ return @[@"onWidgetUrlTriggered", @"onPushReceive", @"onPushOpen", @"onPushRegister", @"onPushDismiss"];
50
49
  }
51
50
 
52
51
  + (BOOL)requiresMainQueueSetup
@@ -69,16 +68,23 @@ NSDictionary* waitingOnPushDismiss = nil;
69
68
  }
70
69
  }
71
70
 
71
+ + (void)handleOpenURL:(NSURL *)url forPushObject:(NetmeraPushObject *)object {
72
+ if (object.pushType == NetmeraPushTypeWebWidget) {
73
+ NSDictionary* urlDictionary = @{@"url" : url.absoluteString};
74
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"onWidgetUrlTriggered" object:nil userInfo:urlDictionary];
75
+ }
76
+ }
77
+
72
78
  + (void)onPushRegister:(NSDictionary *)body {
73
79
  NSData *deviceToken = body[@"pushToken"];
74
80
  const unsigned char *bytes = deviceToken.bytes;
75
-
81
+
76
82
  NSMutableString *deviceTokenString = [NSMutableString string];
77
83
  for (NSUInteger i = 0; i < deviceToken.length; i++) {
78
84
  [deviceTokenString appendFormat:@"%02x", bytes[i]];
79
85
  }
80
86
  NSDictionary* pushToken = @{@"pushToken" : deviceTokenString};
81
-
87
+
82
88
  if (isReactBridgeInitialized) {
83
89
  [[NSNotificationCenter defaultCenter] postNotificationName:@"onPushRegister" object:nil userInfo:pushToken];
84
90
  } else {
@@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
15
15
 
16
16
  +(RNNetmeraUtils *)shared;
17
17
 
18
+ -(NSDictionary *)dictionaryFromCouponObject:(NetmeraCouponObject *)couponObject;
18
19
  -(NSDictionary *)dictionaryFromPushObject:(NetmeraPushObject *)pushObject;
19
20
  -(NetmeraInboxStatus)getInboxStatus:(NSUInteger) code;
20
21
  -(NSDictionary *)parseInboxCountForStatusToMap:(NetmeraInboxCountResponse *) response;
@@ -20,6 +20,20 @@ static RNNetmeraUtils *utils;
20
20
  return utils;
21
21
  }
22
22
 
23
+ -(NSDictionary *)dictionaryFromCouponObject:(NetmeraCouponObject *)couponObject{
24
+ NSTimeInterval assignDateTs = [[couponObject assignDate] timeIntervalSince1970];
25
+ NSTimeInterval expireDateTs = [[couponObject expireDate] timeIntervalSince1970];
26
+
27
+ NSMutableDictionary *data = [NSMutableDictionary dictionary];
28
+ data[@"couponId"] = [couponObject couponId];
29
+ data[@"name"] = [couponObject name];
30
+ data[@"code"] = [couponObject code];
31
+ data[@"assignDate"] = [NSString stringWithFormat:@"%f", assignDateTs];
32
+ data[@"expireDate"] = [NSString stringWithFormat:@"%f", expireDateTs];
33
+
34
+ return data;
35
+ }
36
+
23
37
  -(NSDictionary *)dictionaryFromPushObject:(NetmeraPushObject *)pushObject{
24
38
  NSMutableDictionary *data = [NSMutableDictionary dictionary];
25
39
  data[@"pushType"] = [NSNumber numberWithInteger:[pushObject pushType]];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-netmera",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "Netmera React Native SDK",
5
5
  "main": "index.ts",
6
6
  "author": "netmera",
package/src/Netmera.ts CHANGED
@@ -4,10 +4,10 @@
4
4
 
5
5
  import {
6
6
  AppRegistry,
7
+ DeviceEventEmitter,
7
8
  NativeEventEmitter,
8
9
  NativeModules,
9
10
  NativeModulesStatic,
10
- Platform,
11
11
  } from "react-native";
12
12
  import NetmeraUser from "./models/NetmeraUser";
13
13
  import NetmeraEvent from "./models/NetmeraEvent";
@@ -18,6 +18,8 @@ import NetmeraCategory from "./models/NetmeraCategory";
18
18
  import NMInboxStatusCountFilter from "./models/NMInboxStatusCountFilter";
19
19
  import NMCategoryPreference from "./models/NMCategoryPreference";
20
20
  import { NMInboxStatus } from "./models/NMInboxStatus";
21
+ import NetmeraCouponObject from "./models/NetmeraCouponObject";
22
+ import { isAndroid } from "./utils/DeviceUtils";
21
23
 
22
24
  const { RNNetmera, RNNetmeraRCTEventEmitter }: NativeModulesStatic =
23
25
  NativeModules;
@@ -35,7 +37,7 @@ export default class Netmera {
35
37
  onCarouselObjectSelected?: (message: string) => Promise<void>
36
38
  ) => {
37
39
  if (onPushRegister) {
38
- if (Platform.OS === "android") {
40
+ if (isAndroid()) {
39
41
  AppRegistry.registerHeadlessTask(
40
42
  "onPushRegister",
41
43
  () => onPushRegister
@@ -45,28 +47,28 @@ export default class Netmera {
45
47
  }
46
48
  }
47
49
  if (onPushReceive) {
48
- if (Platform.OS === "android") {
50
+ if (isAndroid()) {
49
51
  AppRegistry.registerHeadlessTask("onPushReceive", () => onPushReceive);
50
52
  } else {
51
53
  netmeraRCTEventEmitter.addListener("onPushReceive", onPushReceive);
52
54
  }
53
55
  }
54
56
  if (onPushOpen) {
55
- if (Platform.OS === "android") {
57
+ if (isAndroid()) {
56
58
  AppRegistry.registerHeadlessTask("onPushOpen", () => onPushOpen);
57
59
  } else {
58
60
  netmeraRCTEventEmitter.addListener("onPushOpen", onPushOpen);
59
61
  }
60
62
  }
61
63
  if (onPushDismiss) {
62
- if (Platform.OS === "android") {
64
+ if (isAndroid()) {
63
65
  AppRegistry.registerHeadlessTask("onPushDismiss", () => onPushDismiss);
64
66
  } else {
65
67
  netmeraRCTEventEmitter.addListener("onPushDismiss", onPushDismiss);
66
68
  }
67
69
  }
68
70
  if (onPushButtonClicked) {
69
- if (Platform.OS === "android") {
71
+ if (isAndroid()) {
70
72
  AppRegistry.registerHeadlessTask(
71
73
  "onPushButtonClicked",
72
74
  () => onPushButtonClicked
@@ -74,7 +76,7 @@ export default class Netmera {
74
76
  }
75
77
  }
76
78
  if (onCarouselObjectSelected) {
77
- if (Platform.OS === "android") {
79
+ if (isAndroid()) {
78
80
  AppRegistry.registerHeadlessTask(
79
81
  "onCarouselObjectSelected",
80
82
  () => onCarouselObjectSelected
@@ -83,6 +85,21 @@ export default class Netmera {
83
85
  }
84
86
  };
85
87
 
88
+ static onWidgetUrlTriggered = (handler: (url: string) => void) => {
89
+ if (isAndroid()) {
90
+ DeviceEventEmitter.addListener("onWidgetUrlTriggered", (eventData) => {
91
+ handler(eventData);
92
+ });
93
+ } else {
94
+ netmeraRCTEventEmitter.addListener(
95
+ "onWidgetUrlTriggered",
96
+ (eventData) => {
97
+ handler(eventData?.url);
98
+ }
99
+ );
100
+ }
101
+ };
102
+
86
103
  static currentExternalId = async (): Promise<string> => {
87
104
  return RNNetmera.currentExternalId();
88
105
  };
@@ -128,7 +145,7 @@ export default class Netmera {
128
145
  };
129
146
 
130
147
  static turnOffSendingEventAndUserUpdate = (turnOff: boolean) => {
131
- if (Platform.OS === "android") {
148
+ if (isAndroid()) {
132
149
  RNNetmera.turnOffSendingEventAndUserUpdate(turnOff);
133
150
  }
134
151
  };
@@ -141,6 +158,13 @@ export default class Netmera {
141
158
  RNNetmera.stopDataTransfer();
142
159
  };
143
160
 
161
+ static fetchCoupons = (
162
+ page: number,
163
+ max: number
164
+ ): Promise<Array<NetmeraCouponObject>> => {
165
+ return RNNetmera.fetchCoupons(page, max);
166
+ };
167
+
144
168
  static fetchInbox = (
145
169
  netmeraInboxFilter: NetmeraInboxFilter
146
170
  ): Promise<Array<NetmeraPushInbox>> => {
@@ -232,7 +256,7 @@ export default class Netmera {
232
256
  from?: string,
233
257
  data?: { [key: string]: string }
234
258
  ) => {
235
- if (Platform.OS === "android" && data) {
259
+ if (isAndroid() && data) {
236
260
  data["google.c.sender.id"] = from ?? "";
237
261
  RNNetmera.onNetmeraPushMessageReceived(data);
238
262
  }
@@ -242,7 +266,7 @@ export default class Netmera {
242
266
  from?: string,
243
267
  data?: { [key: string]: string }
244
268
  ) => {
245
- if (Platform.OS === "android" && data) {
269
+ if (isAndroid() && data) {
246
270
  data["_nm"] = JSON.stringify(data["_nm"]);
247
271
  data["from"] = from ?? "";
248
272
  RNNetmera.onNetmeraPushMessageReceived(data);
@@ -250,16 +274,12 @@ export default class Netmera {
250
274
  };
251
275
 
252
276
  static onNetmeraNewToken = (pushToken: string) => {
253
- if (Platform.OS === "android") {
277
+ if (isAndroid()) {
254
278
  RNNetmera.onNetmeraNewToken(pushToken);
255
279
  }
256
280
  };
257
281
 
258
282
  static isNetmeraRemoteMessage(data?: { [key: string]: string }): boolean {
259
- return (
260
- Platform.OS === "android" &&
261
- data != undefined &&
262
- data.hasOwnProperty("_nm")
263
- );
283
+ return isAndroid() && data != undefined && data.hasOwnProperty("_nm");
264
284
  }
265
285
  }
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Copyright (c) 2023 Netmera Research.
3
+ */
4
+
5
+ export default class NetmeraCouponObject {
6
+ couponId?: string;
7
+ name?: string;
8
+ code?: string;
9
+ assignDate?: string;
10
+ expireDate?: string;
11
+ }
@@ -0,0 +1,9 @@
1
+ import { Platform } from "react-native";
2
+
3
+ export const isAndroid = () => {
4
+ return Platform.OS === "android";
5
+ };
6
+
7
+ export const isIos = () => {
8
+ return Platform.OS === "ios";
9
+ };