react-native-netmera 1.6.2 → 1.6.4
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 +38 -3
- package/RNNetmera.podspec +1 -1
- package/android/.idea/gradle.xml +1 -0
- package/android/.idea/misc.xml +0 -1
- package/android/build.gradle +3 -3
- package/android/src/main/java/com/netmera/reactnativesdk/RNNetmera.java +1 -1
- package/android/src/main/java/com/netmera/reactnativesdk/RNNetmeraConfiguration.java +15 -1
- package/android/src/main/java/com/netmera/reactnativesdk/RNNetmeraModule.java +22 -4
- package/android/src/main/java/com/netmera/reactnativesdk/RNNetmeraWebWidgetCallbacks.java +27 -0
- package/ios/RNNetmera.m +32 -5
- package/ios/RNNetmeraRCTEventEmitter.h +5 -2
- package/ios/RNNetmeraRCTEventEmitter.m +22 -5
- package/package.json +1 -1
- package/src/Netmera.ts +39 -18
- package/src/utils/DeviceUtils.ts +9 -0
package/README.md
CHANGED
|
@@ -210,9 +210,22 @@ export const onPushReceive = async (message) => {
|
|
|
210
210
|
|
|
211
211
|
```
|
|
212
212
|
// For receiving Media Push, you must add Netmera pods to top of your Podfile.
|
|
213
|
-
pod "Netmera", "3.
|
|
214
|
-
pod "Netmera/NotificationServiceExtension", "3.
|
|
215
|
-
pod "Netmera/NotificationContentExtension", "3.
|
|
213
|
+
pod "Netmera", "3.23.1-WithoutDependency"
|
|
214
|
+
pod "Netmera/NotificationServiceExtension", "3.23.1-WithoutDependency"
|
|
215
|
+
pod "Netmera/NotificationContentExtension", "3.23.1-WithoutDependency"
|
|
216
|
+
```
|
|
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
|
+
}
|
|
216
229
|
```
|
|
217
230
|
|
|
218
231
|
### Setup - React Native Part
|
|
@@ -351,6 +364,28 @@ You can send your events as follows. For more examples, please see the [example
|
|
|
351
364
|
}
|
|
352
365
|
```
|
|
353
366
|
|
|
367
|
+
##### Deeplink
|
|
368
|
+
|
|
369
|
+
In order to manage your deeplinks, use the following method instead of `Linking.getInitialURL`
|
|
370
|
+
|
|
371
|
+
```
|
|
372
|
+
Netmera.getInitialURL(url => {
|
|
373
|
+
console.log(url);
|
|
374
|
+
});
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
You can use other `Linking` methods as before
|
|
378
|
+
|
|
379
|
+
##### Widget URL Callback
|
|
380
|
+
|
|
381
|
+
In order to use the widget URL callback, use `onWidgetUrlTriggered` method as follows.
|
|
382
|
+
|
|
383
|
+
```
|
|
384
|
+
Netmera.onWidgetUrlTriggered(url => {
|
|
385
|
+
console.log('Netmera triggered widget url: ', url);
|
|
386
|
+
});
|
|
387
|
+
```
|
|
388
|
+
|
|
354
389
|
##### Push Notification Permissions
|
|
355
390
|
|
|
356
391
|
If you don't request notification permission at runtime, you can request it by calling the `requestPushNotificationAuthorization()` method.
|
package/RNNetmera.podspec
CHANGED
package/android/.idea/gradle.xml
CHANGED
|
@@ -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>
|
package/android/.idea/misc.xml
CHANGED
package/android/build.gradle
CHANGED
|
@@ -15,8 +15,8 @@ android {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
dependencies {
|
|
18
|
-
implementation 'com.netmera:nmcore:3.
|
|
19
|
-
implementation 'com.netmera:nmfcm:3.
|
|
20
|
-
implementation 'com.netmera:nmhms:3.
|
|
18
|
+
implementation 'com.netmera:nmcore:3.11.5'
|
|
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.
|
|
26
|
+
headerValues.put("X-netmera-frameworkV", "1.6.4");
|
|
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
|
|
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;
|
|
@@ -30,6 +30,7 @@ import com.netmera.callbacks.NMCategoryPreferenceFetchCallback;
|
|
|
30
30
|
import com.netmera.callbacks.NMCategoryPreferenceSetCallback;
|
|
31
31
|
import com.netmera.callbacks.NMFetchCouponsResultListener;
|
|
32
32
|
import com.netmera.callbacks.NMInboxCountResultListener;
|
|
33
|
+
import com.netmera.callbacks.NMUpdateUserListener;
|
|
33
34
|
import com.netmera.data.NMCategoryPreference;
|
|
34
35
|
import com.netmera.data.NMCouponDetail;
|
|
35
36
|
import com.netmera.data.NMInboxStatusCount;
|
|
@@ -70,6 +71,9 @@ public class RNNetmeraModule extends ReactContextBaseJavaModule {
|
|
|
70
71
|
private static final String ERROR_MESSAGE_SET_CATEGORY_PREFERENCE = "Error occurred while setting user category preference list.";
|
|
71
72
|
private static final String ERROR_CODE_COUPON_FETCH = "2026";
|
|
72
73
|
private static final String ERROR_MESSAGE_COUPON_FETCH = "Error occurred while fetching coupons.";
|
|
74
|
+
private static final String ERROR_CODE_UPDATE_USER = "2027";
|
|
75
|
+
private static final String ERROR_MESSAGE_UPDATE_USER = "Error occurred while updating user. Reason: ";
|
|
76
|
+
|
|
73
77
|
|
|
74
78
|
public static ReactApplicationContext reactContext;
|
|
75
79
|
private NetmeraInbox netmeraInbox;
|
|
@@ -294,7 +298,7 @@ public class RNNetmeraModule extends ReactContextBaseJavaModule {
|
|
|
294
298
|
}
|
|
295
299
|
|
|
296
300
|
@ReactMethod
|
|
297
|
-
public void updateUser(ReadableMap readableMap) {
|
|
301
|
+
public void updateUser(ReadableMap readableMap, final Promise promise) {
|
|
298
302
|
Map userMap = RNNetmeraUtil.toMap(readableMap);
|
|
299
303
|
userMap.values().removeAll(Collections.singleton(null));
|
|
300
304
|
RNNetmeraUser netmeraUser = new RNNetmeraUser();
|
|
@@ -315,7 +319,17 @@ public class RNNetmeraModule extends ReactContextBaseJavaModule {
|
|
|
315
319
|
}
|
|
316
320
|
|
|
317
321
|
netmeraUser.setUserParameters(userMap);
|
|
318
|
-
Netmera.updateUser(netmeraUser)
|
|
322
|
+
Netmera.updateUser(netmeraUser, new NMUpdateUserListener() {
|
|
323
|
+
@Override
|
|
324
|
+
public void onSuccess() {
|
|
325
|
+
promise.resolve(null);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
@Override
|
|
329
|
+
public void onFailure(@Nullable String s) {
|
|
330
|
+
promise.reject(ERROR_CODE_UPDATE_USER, ERROR_MESSAGE_UPDATE_USER + s);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
319
333
|
}
|
|
320
334
|
|
|
321
335
|
@ReactMethod
|
|
@@ -549,4 +563,8 @@ public class RNNetmeraModule extends ReactContextBaseJavaModule {
|
|
|
549
563
|
private boolean hasKey(ReadableMap map, String key) {
|
|
550
564
|
return map.hasKey(key) && !map.isNull(key);
|
|
551
565
|
}
|
|
566
|
+
|
|
567
|
+
public static void emitEvent(String eventName, String eventData) {
|
|
568
|
+
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, eventData);
|
|
569
|
+
}
|
|
552
570
|
}
|
|
@@ -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
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
//
|
|
2
2
|
// RNNetmera.m
|
|
3
|
-
// Netmera SDK
|
|
4
3
|
//
|
|
5
|
-
// Created by
|
|
4
|
+
// Created by Initial Code
|
|
6
5
|
// Copyright © 2019 Netmera. All rights reserved.
|
|
7
6
|
//
|
|
8
7
|
|
|
@@ -12,6 +11,7 @@
|
|
|
12
11
|
#import "RNNetmeraUtils.h"
|
|
13
12
|
#import "RNNetmeraCategoryObject.h"
|
|
14
13
|
#import <Netmera/Netmera.h>
|
|
14
|
+
#import <RNNetmera/RNNetmeraRCTEventEmitter.h>
|
|
15
15
|
|
|
16
16
|
NSString *const ERROR_CODE_INBOX = @"2016";
|
|
17
17
|
NSString *const ERROR_MESSAGE_INBOX = @"There was a problem fetching inbox";
|
|
@@ -33,6 +33,8 @@ 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
34
|
NSString *const ERROR_CODE_COUPON_FETCH = @"2026";
|
|
35
35
|
NSString *const ERROR_MESSAGE_COUPON_FETCH = @"Error occurred while fetching coupons.";
|
|
36
|
+
NSString *const ERROR_CODE_UPDATE_USER = @"2027";
|
|
37
|
+
NSString *const ERROR_MESSAGE_UPDATE_USER = @"Error occurred while updating user. Reason: ";
|
|
36
38
|
|
|
37
39
|
@implementation RNNetmera
|
|
38
40
|
|
|
@@ -44,11 +46,16 @@ NSString *const ERROR_MESSAGE_COUPON_FETCH = @"Error occurred while fetching cou
|
|
|
44
46
|
[Netmera start];
|
|
45
47
|
[Netmera setAPIKey:apiKey];
|
|
46
48
|
[self setNetmeraHeaders];
|
|
49
|
+
[Netmera setDeeplinkCallback:^(NSURL * _Nullable url, NetmeraPushObject * _Nullable pushObject) {
|
|
50
|
+
if (url != nil) {
|
|
51
|
+
[RNNetmeraRCTEventEmitter onDeeplinkTriggered:url];
|
|
52
|
+
}
|
|
53
|
+
}];
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
+ (void)setNetmeraHeaders {
|
|
50
57
|
[Netmera setFramework:@"react"];
|
|
51
|
-
[Netmera setFrameworkVersion:@"1.6.
|
|
58
|
+
[Netmera setFrameworkVersion:@"1.6.4"];
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
+ (void)setPushDelegate:(NSObject<NetmeraPushDelegate> *)delegate {
|
|
@@ -267,7 +274,9 @@ RCT_EXPORT_METHOD(sendEvent:(NSDictionary *)eventDictionary) {
|
|
|
267
274
|
[Netmera sendEvent:event];
|
|
268
275
|
}
|
|
269
276
|
|
|
270
|
-
RCT_EXPORT_METHOD(updateUser:(NSDictionary *)userDictionary
|
|
277
|
+
RCT_EXPORT_METHOD(updateUser:(NSDictionary *)userDictionary
|
|
278
|
+
resolver: (RCTPromiseResolveBlock)resolve
|
|
279
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
271
280
|
NSMutableDictionary *userMutableDictionary = [userDictionary mutableCopy];
|
|
272
281
|
NSArray *keysForNullValues = [userMutableDictionary allKeysForObject:[NSNull null]];
|
|
273
282
|
[userMutableDictionary removeObjectsForKeys:keysForNullValues];
|
|
@@ -281,7 +290,20 @@ RCT_EXPORT_METHOD(updateUser:(NSDictionary *)userDictionary) {
|
|
|
281
290
|
[userMutableDictionary removeObjectForKey:@"msisdn"];
|
|
282
291
|
|
|
283
292
|
user.userParameters = userMutableDictionary;
|
|
284
|
-
[Netmera updateUser:user
|
|
293
|
+
[Netmera updateUser:user completion:^(BOOL isSuccess, NSError * _Nullable error) {
|
|
294
|
+
if (error != nil) {
|
|
295
|
+
NSString* errorMessage;
|
|
296
|
+
if (error.userInfo[@"com.netmera.response.object"]) {
|
|
297
|
+
NSDictionary *errorData = error.userInfo[@"com.netmera.response.object"];
|
|
298
|
+
errorMessage = errorData[@"error"];
|
|
299
|
+
} else {
|
|
300
|
+
errorMessage = nil;
|
|
301
|
+
}
|
|
302
|
+
reject(ERROR_CODE_UPDATE_USER, [NSString stringWithFormat:@"%@%@", ERROR_MESSAGE_UPDATE_USER, errorMessage], nil);
|
|
303
|
+
} else {
|
|
304
|
+
resolve(nil);
|
|
305
|
+
}
|
|
306
|
+
}];
|
|
285
307
|
}
|
|
286
308
|
|
|
287
309
|
RCT_EXPORT_METHOD(setApiKey:(NSString *)apiKey) {
|
|
@@ -392,6 +414,11 @@ RCT_EXPORT_METHOD(updateAll:(NSInteger)inboxStatus
|
|
|
392
414
|
}
|
|
393
415
|
}
|
|
394
416
|
|
|
417
|
+
RCT_EXPORT_METHOD(getInitialURL:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
418
|
+
NSURL *url = [RNNetmeraRCTEventEmitter getInitialUrl];
|
|
419
|
+
resolve(url.absoluteString);
|
|
420
|
+
}
|
|
421
|
+
|
|
395
422
|
RCT_EXPORT_METHOD(getInboxCountForStatus:(NSDictionary *) filterDictionary
|
|
396
423
|
resolver: (RCTPromiseResolveBlock)resolve
|
|
397
424
|
rejecter: (RCTPromiseRejectBlock)reject) {
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
//
|
|
2
2
|
// RNNetmeraRCTEventEmitter.h
|
|
3
|
-
// Netmera SDK
|
|
4
3
|
//
|
|
5
|
-
// Created by
|
|
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
|
|
|
14
|
+
+(NSURL *) getInitialUrl;
|
|
15
|
+
+(void) handleOpenURL:(NSURL *)url forPushObject:(NetmeraPushObject *)object;
|
|
16
|
+
+(void) onDeeplinkTriggered:(NSURL *)url;
|
|
14
17
|
+(void) onPushRegister:(NSDictionary*)dict;
|
|
15
18
|
+(void) onPushReceive:(NSDictionary*)dict;
|
|
16
19
|
+(void) onPushDismiss:(NSDictionary*)dict;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
//
|
|
2
2
|
// RNNetmeraRCTEventEmitter.m
|
|
3
|
-
// Netmera SDK
|
|
4
3
|
//
|
|
5
|
-
// Created by
|
|
4
|
+
// Created by Initial Code
|
|
6
5
|
// Copyright © 2019 Netmera. All rights reserved.
|
|
7
6
|
//
|
|
8
7
|
|
|
@@ -14,6 +13,7 @@ RCT_EXPORT_MODULE();
|
|
|
14
13
|
|
|
15
14
|
bool isReactBridgeInitialized;
|
|
16
15
|
|
|
16
|
+
NSURL* waitingDeeplink = nil;
|
|
17
17
|
NSDictionary* waitingOnPushRegister = nil;
|
|
18
18
|
NSDictionary* waitingOnPushReceive = nil;
|
|
19
19
|
NSDictionary* waitingOnPushOpen = nil;
|
|
@@ -46,7 +46,7 @@ NSDictionary* waitingOnPushDismiss = nil;
|
|
|
46
46
|
|
|
47
47
|
- (NSArray<NSString *> *)supportedEvents
|
|
48
48
|
{
|
|
49
|
-
return @[@"onPushReceive", @"onPushOpen", @"onPushRegister", @"onPushDismiss"];
|
|
49
|
+
return @[@"onWidgetUrlTriggered", @"onPushReceive", @"onPushOpen", @"onPushRegister", @"onPushDismiss"];
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
+ (BOOL)requiresMainQueueSetup
|
|
@@ -69,16 +69,33 @@ NSDictionary* waitingOnPushDismiss = nil;
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
+ (NSURL * _Nullable)getInitialUrl {
|
|
73
|
+
return waitingDeeplink;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
+ (void)handleOpenURL:(NSURL *)url forPushObject:(NetmeraPushObject *)object {
|
|
77
|
+
if (object.pushType == NetmeraPushTypeWebWidget) {
|
|
78
|
+
NSDictionary* urlDictionary = @{@"url" : url.absoluteString};
|
|
79
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:@"onWidgetUrlTriggered" object:nil userInfo:urlDictionary];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
+ (void)onDeeplinkTriggered:(NSURL *)url {
|
|
84
|
+
if (!isReactBridgeInitialized) {
|
|
85
|
+
waitingDeeplink = url;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
72
89
|
+ (void)onPushRegister:(NSDictionary *)body {
|
|
73
90
|
NSData *deviceToken = body[@"pushToken"];
|
|
74
91
|
const unsigned char *bytes = deviceToken.bytes;
|
|
75
|
-
|
|
92
|
+
|
|
76
93
|
NSMutableString *deviceTokenString = [NSMutableString string];
|
|
77
94
|
for (NSUInteger i = 0; i < deviceToken.length; i++) {
|
|
78
95
|
[deviceTokenString appendFormat:@"%02x", bytes[i]];
|
|
79
96
|
}
|
|
80
97
|
NSDictionary* pushToken = @{@"pushToken" : deviceTokenString};
|
|
81
|
-
|
|
98
|
+
|
|
82
99
|
if (isReactBridgeInitialized) {
|
|
83
100
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"onPushRegister" object:nil userInfo:pushToken];
|
|
84
101
|
} else {
|
package/package.json
CHANGED
package/src/Netmera.ts
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
AppRegistry,
|
|
7
|
+
DeviceEventEmitter,
|
|
8
|
+
Linking,
|
|
7
9
|
NativeEventEmitter,
|
|
8
10
|
NativeModules,
|
|
9
11
|
NativeModulesStatic,
|
|
10
|
-
Platform,
|
|
11
12
|
} from "react-native";
|
|
12
13
|
import NetmeraUser from "./models/NetmeraUser";
|
|
13
14
|
import NetmeraEvent from "./models/NetmeraEvent";
|
|
@@ -19,6 +20,7 @@ import NMInboxStatusCountFilter from "./models/NMInboxStatusCountFilter";
|
|
|
19
20
|
import NMCategoryPreference from "./models/NMCategoryPreference";
|
|
20
21
|
import { NMInboxStatus } from "./models/NMInboxStatus";
|
|
21
22
|
import NetmeraCouponObject from "./models/NetmeraCouponObject";
|
|
23
|
+
import { isAndroid, isIos } from "./utils/DeviceUtils";
|
|
22
24
|
|
|
23
25
|
const { RNNetmera, RNNetmeraRCTEventEmitter }: NativeModulesStatic =
|
|
24
26
|
NativeModules;
|
|
@@ -36,7 +38,7 @@ export default class Netmera {
|
|
|
36
38
|
onCarouselObjectSelected?: (message: string) => Promise<void>
|
|
37
39
|
) => {
|
|
38
40
|
if (onPushRegister) {
|
|
39
|
-
if (
|
|
41
|
+
if (isAndroid()) {
|
|
40
42
|
AppRegistry.registerHeadlessTask(
|
|
41
43
|
"onPushRegister",
|
|
42
44
|
() => onPushRegister
|
|
@@ -46,28 +48,28 @@ export default class Netmera {
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
if (onPushReceive) {
|
|
49
|
-
if (
|
|
51
|
+
if (isAndroid()) {
|
|
50
52
|
AppRegistry.registerHeadlessTask("onPushReceive", () => onPushReceive);
|
|
51
53
|
} else {
|
|
52
54
|
netmeraRCTEventEmitter.addListener("onPushReceive", onPushReceive);
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
if (onPushOpen) {
|
|
56
|
-
if (
|
|
58
|
+
if (isAndroid()) {
|
|
57
59
|
AppRegistry.registerHeadlessTask("onPushOpen", () => onPushOpen);
|
|
58
60
|
} else {
|
|
59
61
|
netmeraRCTEventEmitter.addListener("onPushOpen", onPushOpen);
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
if (onPushDismiss) {
|
|
63
|
-
if (
|
|
65
|
+
if (isAndroid()) {
|
|
64
66
|
AppRegistry.registerHeadlessTask("onPushDismiss", () => onPushDismiss);
|
|
65
67
|
} else {
|
|
66
68
|
netmeraRCTEventEmitter.addListener("onPushDismiss", onPushDismiss);
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
if (onPushButtonClicked) {
|
|
70
|
-
if (
|
|
72
|
+
if (isAndroid()) {
|
|
71
73
|
AppRegistry.registerHeadlessTask(
|
|
72
74
|
"onPushButtonClicked",
|
|
73
75
|
() => onPushButtonClicked
|
|
@@ -75,7 +77,7 @@ export default class Netmera {
|
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
if (onCarouselObjectSelected) {
|
|
78
|
-
if (
|
|
80
|
+
if (isAndroid()) {
|
|
79
81
|
AppRegistry.registerHeadlessTask(
|
|
80
82
|
"onCarouselObjectSelected",
|
|
81
83
|
() => onCarouselObjectSelected
|
|
@@ -84,6 +86,21 @@ export default class Netmera {
|
|
|
84
86
|
}
|
|
85
87
|
};
|
|
86
88
|
|
|
89
|
+
static onWidgetUrlTriggered = (handler: (url: string) => void) => {
|
|
90
|
+
if (isAndroid()) {
|
|
91
|
+
DeviceEventEmitter.addListener("onWidgetUrlTriggered", (eventData) => {
|
|
92
|
+
handler(eventData);
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
netmeraRCTEventEmitter.addListener(
|
|
96
|
+
"onWidgetUrlTriggered",
|
|
97
|
+
(eventData) => {
|
|
98
|
+
handler(eventData?.url);
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
87
104
|
static currentExternalId = async (): Promise<string> => {
|
|
88
105
|
return RNNetmera.currentExternalId();
|
|
89
106
|
};
|
|
@@ -129,7 +146,7 @@ export default class Netmera {
|
|
|
129
146
|
};
|
|
130
147
|
|
|
131
148
|
static turnOffSendingEventAndUserUpdate = (turnOff: boolean) => {
|
|
132
|
-
if (
|
|
149
|
+
if (isAndroid()) {
|
|
133
150
|
RNNetmera.turnOffSendingEventAndUserUpdate(turnOff);
|
|
134
151
|
}
|
|
135
152
|
};
|
|
@@ -185,8 +202,8 @@ export default class Netmera {
|
|
|
185
202
|
RNNetmera.sendEvent(event);
|
|
186
203
|
};
|
|
187
204
|
|
|
188
|
-
static updateUser = (user: NetmeraUser) => {
|
|
189
|
-
RNNetmera.updateUser(user);
|
|
205
|
+
static updateUser = (user: NetmeraUser): Promise<void> => {
|
|
206
|
+
return RNNetmera.updateUser(user);
|
|
190
207
|
};
|
|
191
208
|
|
|
192
209
|
static updateAll = (inboxStatus: number) => {
|
|
@@ -240,7 +257,7 @@ export default class Netmera {
|
|
|
240
257
|
from?: string,
|
|
241
258
|
data?: { [key: string]: string }
|
|
242
259
|
) => {
|
|
243
|
-
if (
|
|
260
|
+
if (isAndroid() && data) {
|
|
244
261
|
data["google.c.sender.id"] = from ?? "";
|
|
245
262
|
RNNetmera.onNetmeraPushMessageReceived(data);
|
|
246
263
|
}
|
|
@@ -250,7 +267,7 @@ export default class Netmera {
|
|
|
250
267
|
from?: string,
|
|
251
268
|
data?: { [key: string]: string }
|
|
252
269
|
) => {
|
|
253
|
-
if (
|
|
270
|
+
if (isAndroid() && data) {
|
|
254
271
|
data["_nm"] = JSON.stringify(data["_nm"]);
|
|
255
272
|
data["from"] = from ?? "";
|
|
256
273
|
RNNetmera.onNetmeraPushMessageReceived(data);
|
|
@@ -258,16 +275,20 @@ export default class Netmera {
|
|
|
258
275
|
};
|
|
259
276
|
|
|
260
277
|
static onNetmeraNewToken = (pushToken: string) => {
|
|
261
|
-
if (
|
|
278
|
+
if (isAndroid()) {
|
|
262
279
|
RNNetmera.onNetmeraNewToken(pushToken);
|
|
263
280
|
}
|
|
264
281
|
};
|
|
265
282
|
|
|
266
283
|
static isNetmeraRemoteMessage(data?: { [key: string]: string }): boolean {
|
|
267
|
-
return (
|
|
268
|
-
Platform.OS === "android" &&
|
|
269
|
-
data != undefined &&
|
|
270
|
-
data.hasOwnProperty("_nm")
|
|
271
|
-
);
|
|
284
|
+
return isAndroid() && data != undefined && data.hasOwnProperty("_nm");
|
|
272
285
|
}
|
|
286
|
+
|
|
287
|
+
static getInitialURL = async () => {
|
|
288
|
+
if (isIos()) {
|
|
289
|
+
return RNNetmera.getInitialURL();
|
|
290
|
+
} else {
|
|
291
|
+
return Linking.getInitialURL();
|
|
292
|
+
}
|
|
293
|
+
};
|
|
273
294
|
}
|