@trycourier/courier-react-native 5.5.7 → 5.5.9
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.9")
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
|
|
@@ -33,7 +33,7 @@ static NSString *const CourierForegroundOptionsDidChangeNotification = @"iosFore
|
|
|
33
33
|
if (self) {
|
|
34
34
|
|
|
35
35
|
// Set the user agent
|
|
36
|
-
Courier.agent = [CourierAgent reactNativeIOS:@"5.5.
|
|
36
|
+
Courier.agent = [CourierAgent reactNativeIOS:@"5.5.9"];
|
|
37
37
|
|
|
38
38
|
// Register for remote notifications
|
|
39
39
|
UIApplication *app = [UIApplication sharedApplication];
|
|
@@ -57,7 +57,7 @@ static NSString *const CourierForegroundOptionsDidChangeNotification = @"iosFore
|
|
|
57
57
|
|
|
58
58
|
[[NSNotificationCenter defaultCenter]
|
|
59
59
|
addObserver:self
|
|
60
|
-
selector:@selector(
|
|
60
|
+
selector:@selector(onReactNativeReady:)
|
|
61
61
|
name:RCTContentDidAppearNotification
|
|
62
62
|
object:nil];
|
|
63
63
|
}
|
|
@@ -66,7 +66,7 @@ static NSString *const CourierForegroundOptionsDidChangeNotification = @"iosFore
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// Called when React Native is loaded and ready
|
|
69
|
-
- (void)
|
|
69
|
+
- (void)onReactNativeReady:(__unused NSNotification *)note
|
|
70
70
|
{
|
|
71
71
|
self.isReactNativeReady = YES;
|
|
72
72
|
|
|
@@ -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.9")
|
|
18
18
|
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
//
|
|
7
7
|
|
|
8
8
|
import Courier_iOS
|
|
9
|
+
import React
|
|
9
10
|
|
|
10
11
|
@objc(CourierSystemModule)
|
|
11
12
|
class CourierSystemModule: CourierReactNativeEventEmitter {
|
|
12
13
|
|
|
14
|
+
private var isReactNativeReady: Bool = false
|
|
13
15
|
private var lastClickedMessage: [AnyHashable: Any]? = nil
|
|
14
16
|
private var notificationCenter: NotificationCenter {
|
|
15
17
|
get { return NotificationCenter.default }
|
|
@@ -38,6 +40,30 @@ class CourierSystemModule: CourierReactNativeEventEmitter {
|
|
|
38
40
|
object: nil
|
|
39
41
|
)
|
|
40
42
|
|
|
43
|
+
notificationCenter.addObserver(
|
|
44
|
+
self,
|
|
45
|
+
selector: #selector(onReactNativeReady),
|
|
46
|
+
name: NSNotification.Name(rawValue: "RCTContentDidAppearNotification"),
|
|
47
|
+
object: nil
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
notificationCenter.addObserver(
|
|
51
|
+
self,
|
|
52
|
+
selector: #selector(onBridgeWillReload),
|
|
53
|
+
name: NSNotification.Name(rawValue: "RCTBridgeWillReloadNotification"),
|
|
54
|
+
object: nil
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// MARK: - RN Lifecycle Notifications
|
|
60
|
+
|
|
61
|
+
@objc private func onReactNativeReady(_ notification: Notification) {
|
|
62
|
+
isReactNativeReady = true
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@objc private func onBridgeWillReload(_ notification: Notification) {
|
|
66
|
+
isReactNativeReady = false
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
@objc private func pushNotificationClicked(notification: Notification) {
|
|
@@ -70,16 +96,30 @@ class CourierSystemModule: CourierReactNativeEventEmitter {
|
|
|
70
96
|
}
|
|
71
97
|
|
|
72
98
|
@objc func registerPushNotificationClickedOnKilledState() {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
99
|
+
let pollInterval: UInt64 = 250_000_000 // 250ms
|
|
100
|
+
let timeout: UInt64 = 10_000_000_000 // 10s
|
|
101
|
+
|
|
102
|
+
// Poll until react native is ready
|
|
103
|
+
Task.detached(priority: .background) { [weak self] in
|
|
104
|
+
guard let self else { return }
|
|
105
|
+
|
|
106
|
+
let start = DispatchTime.now().uptimeNanoseconds
|
|
107
|
+
|
|
108
|
+
// Hold until react native is ready
|
|
109
|
+
while !self.isReactNativeReady, DispatchTime.now().uptimeNanoseconds - start < timeout {
|
|
110
|
+
try? await Task.sleep(nanoseconds: pollInterval)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// If possible, broadcast the message
|
|
114
|
+
await MainActor.run {
|
|
115
|
+
guard self.isReactNativeReady, let message = self.lastClickedMessage else {
|
|
116
|
+
NSLog("[Courier] Timed out waiting for React Native or no message available.")
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
self.broadcast(name: PushEvents.CLICKED_EVENT, message: message)
|
|
121
|
+
}
|
|
76
122
|
}
|
|
77
|
-
|
|
78
|
-
broadcast(
|
|
79
|
-
name: PushEvents.CLICKED_EVENT,
|
|
80
|
-
message: message
|
|
81
|
-
)
|
|
82
|
-
|
|
83
123
|
}
|
|
84
124
|
|
|
85
125
|
// MARK: Open App
|