@trycourier/courier-react-native 5.5.4 → 5.5.6
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.
|
@@ -15,7 +15,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
|
15
15
|
import com.google.gson.GsonBuilder
|
|
16
16
|
|
|
17
17
|
internal object Utils {
|
|
18
|
-
val COURIER_AGENT = CourierAgent.ReactNativeAndroid(version = "5.5.
|
|
18
|
+
val COURIER_AGENT = CourierAgent.ReactNativeAndroid(version = "5.5.6")
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
|
|
@@ -7,12 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
@import Courier_iOS;
|
|
9
9
|
#import "CourierReactNativeDelegate.h"
|
|
10
|
+
#import <React/RCTBridge.h>
|
|
11
|
+
#import <React/RCTBridge+Private.h>
|
|
12
|
+
#import <React/RCTUtils.h>
|
|
13
|
+
|
|
10
14
|
#pragma GCC diagnostic ignored "-Wprotocol"
|
|
11
15
|
#pragma clang diagnostic ignored "-Wprotocol"
|
|
12
16
|
|
|
13
17
|
@interface CourierReactNativeDelegate ()
|
|
14
18
|
|
|
15
19
|
@property (nonatomic, assign) UNNotificationPresentationOptions notificationPresentationOptions;
|
|
20
|
+
@property (nonatomic, strong) NSDictionary *pendingNotificationClick;
|
|
21
|
+
@property (nonatomic, assign) BOOL isReactNativeReady;
|
|
16
22
|
|
|
17
23
|
@end
|
|
18
24
|
|
|
@@ -25,80 +31,111 @@ static NSString *const CourierForegroundOptionsDidChangeNotification = @"iosFore
|
|
|
25
31
|
|
|
26
32
|
if (self) {
|
|
27
33
|
// Set the user agent
|
|
28
|
-
Courier.agent = [CourierAgent reactNativeIOS:@"5.5.
|
|
34
|
+
Courier.agent = [CourierAgent reactNativeIOS:@"5.5.6"];
|
|
29
35
|
|
|
30
36
|
// Register for remote notifications
|
|
31
37
|
UIApplication *app = [UIApplication sharedApplication];
|
|
32
38
|
[app registerForRemoteNotifications];
|
|
33
39
|
|
|
34
|
-
//
|
|
40
|
+
// Set notification center delegate
|
|
35
41
|
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
36
42
|
center.delegate = self;
|
|
37
43
|
|
|
44
|
+
// Detect JS bridge load
|
|
45
|
+
self.isReactNativeReady = [self detectIfBridgeIsReady];
|
|
46
|
+
|
|
47
|
+
[[NSNotificationCenter defaultCenter]
|
|
48
|
+
addObserver:self
|
|
49
|
+
selector:@selector(onJavaScriptDidLoad:)
|
|
50
|
+
name:RCTJavaScriptDidLoadNotification
|
|
51
|
+
object:nil];
|
|
52
|
+
|
|
38
53
|
[[NSNotificationCenter defaultCenter]
|
|
39
54
|
addObserver:self
|
|
40
55
|
selector:@selector(notificationPresentationOptionsUpdate:)
|
|
41
56
|
name:CourierForegroundOptionsDidChangeNotification
|
|
42
|
-
object:nil
|
|
43
|
-
];
|
|
57
|
+
object:nil];
|
|
44
58
|
}
|
|
45
59
|
|
|
46
60
|
return self;
|
|
47
61
|
}
|
|
48
62
|
|
|
63
|
+
- (BOOL)detectIfBridgeIsReady {
|
|
64
|
+
// RCTBridge currentBridge is non-nil only after JS is loaded
|
|
65
|
+
return [RCTBridge currentBridge] != nil;
|
|
66
|
+
}
|
|
67
|
+
|
|
49
68
|
- (void)notificationPresentationOptionsUpdate:(NSNotification *)notification
|
|
50
69
|
{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
70
|
+
NSDictionary *userInfo = notification.userInfo;
|
|
71
|
+
self.notificationPresentationOptions = ((NSNumber *)[userInfo objectForKey:@"options"]).unsignedIntegerValue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
- (void)onJavaScriptDidLoad:(NSNotification *)notification
|
|
75
|
+
{
|
|
76
|
+
self.isReactNativeReady = YES;
|
|
77
|
+
|
|
78
|
+
if (self.pendingNotificationClick) {
|
|
79
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked"
|
|
80
|
+
object:nil
|
|
81
|
+
userInfo:self.pendingNotificationClick];
|
|
82
|
+
self.pendingNotificationClick = nil;
|
|
55
83
|
}
|
|
56
84
|
}
|
|
57
85
|
|
|
58
86
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
|
59
|
-
|
|
60
|
-
withCompletionHandler:(void (^)(
|
|
87
|
+
didReceiveNotificationResponse:(UNNotificationResponse *)response
|
|
88
|
+
withCompletionHandler:(void (^)(void))completionHandler
|
|
61
89
|
{
|
|
62
|
-
UNNotificationContent *content = notification.request.content;
|
|
90
|
+
UNNotificationContent *content = response.notification.request.content;
|
|
63
91
|
NSDictionary *message = content.userInfo;
|
|
64
|
-
|
|
65
|
-
[message trackMessageWithEvent:
|
|
92
|
+
|
|
93
|
+
[message trackMessageWithEvent:CourierTrackingEventClicked completion:^(NSError * _Nullable error) {
|
|
66
94
|
if (error) {
|
|
67
|
-
NSLog(@"Error tracking message: %@", error.localizedDescription);
|
|
95
|
+
NSLog(@"[Courier] Error tracking message: %@", error.localizedDescription);
|
|
68
96
|
}
|
|
69
97
|
}];
|
|
70
|
-
|
|
98
|
+
|
|
99
|
+
NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
|
|
100
|
+
|
|
71
101
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
102
|
+
if (self.isReactNativeReady) {
|
|
103
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked"
|
|
104
|
+
object:nil
|
|
105
|
+
userInfo:pushNotification];
|
|
106
|
+
} else {
|
|
107
|
+
self.pendingNotificationClick = pushNotification;
|
|
108
|
+
}
|
|
109
|
+
completionHandler();
|
|
75
110
|
});
|
|
76
111
|
}
|
|
77
112
|
|
|
78
113
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
|
79
|
-
|
|
80
|
-
withCompletionHandler:(void (^)(
|
|
114
|
+
willPresentNotification:(UNNotification *)notification
|
|
115
|
+
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
|
|
81
116
|
{
|
|
82
|
-
UNNotificationContent *content =
|
|
117
|
+
UNNotificationContent *content = notification.request.content;
|
|
83
118
|
NSDictionary *message = content.userInfo;
|
|
84
|
-
|
|
85
|
-
[message trackMessageWithEvent:
|
|
119
|
+
|
|
120
|
+
[message trackMessageWithEvent:CourierTrackingEventDelivered completion:^(NSError * _Nullable error) {
|
|
86
121
|
if (error) {
|
|
87
|
-
NSLog(@"Error tracking
|
|
122
|
+
NSLog(@"[Courier] Error tracking delivery: %@", error.localizedDescription);
|
|
88
123
|
}
|
|
89
124
|
}];
|
|
90
125
|
|
|
91
126
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
92
127
|
NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
|
|
93
|
-
[[NSNotificationCenter defaultCenter] postNotificationName:@"
|
|
94
|
-
|
|
128
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationDelivered"
|
|
129
|
+
object:nil
|
|
130
|
+
userInfo:pushNotification];
|
|
131
|
+
completionHandler(self.notificationPresentationOptions);
|
|
95
132
|
});
|
|
96
133
|
}
|
|
97
134
|
|
|
98
135
|
- (void)application:(UIApplication *)application
|
|
99
136
|
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
|
|
100
137
|
{
|
|
101
|
-
NSLog(@"Failed to register for remote
|
|
138
|
+
NSLog(@"[Courier] Failed to register for remote notifications: %@", error.localizedDescription);
|
|
102
139
|
}
|
|
103
140
|
|
|
104
141
|
- (void)application:(UIApplication *)application
|
|
@@ -14,7 +14,7 @@ internal class CourierReactNativeEventEmitter: RCTEventEmitter {
|
|
|
14
14
|
|
|
15
15
|
// Set the user agent
|
|
16
16
|
// Used to know the platform performing requests
|
|
17
|
-
Courier.agent = CourierAgent.reactNativeIOS("5.5.
|
|
17
|
+
Courier.agent = CourierAgent.reactNativeIOS("5.5.6")
|
|
18
18
|
|
|
19
19
|
}
|
|
20
20
|
|