@trycourier/courier-react-native 5.5.2 → 5.5.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 +23 -9
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +1 -29
- package/android/src/main/java/com/courierreactnative/CourierSystemModule.kt +20 -3
- package/android/src/main/java/com/courierreactnative/Utils.kt +1 -1
- package/ios/CourierReactNativeDelegate.m +1 -1
- package/ios/CourierReactNativeEventEmitter.swift +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -118,12 +118,11 @@ Your app must support at least gradle `8.4`
|
|
|
118
118
|
|
|
119
119
|
 
|
|
120
120
|
|
|
121
|
-
### 3. Extend
|
|
122
|
-
|
|
123
|
-
In your Android project, change your `MainActivity` to extend the `CourierReactNativeActivity`.
|
|
121
|
+
### 3. Extend your `MainActivity` with `CourierReactNativeActivity`
|
|
124
122
|
|
|
125
123
|
This allows the Courier SDK to manage the current user between app sessions.
|
|
126
124
|
|
|
125
|
+
Java
|
|
127
126
|
```java
|
|
128
127
|
import com.courierreactnative.CourierReactNativeActivity;
|
|
129
128
|
|
|
@@ -132,6 +131,15 @@ public class MainActivity extends CourierReactNativeActivity {
|
|
|
132
131
|
}
|
|
133
132
|
```
|
|
134
133
|
|
|
134
|
+
Kotlin
|
|
135
|
+
```kotlin
|
|
136
|
+
import com.courierreactnative.CourierReactNativeActivity;
|
|
137
|
+
|
|
138
|
+
class MainActivity : CourierReactNativeActivity() {
|
|
139
|
+
..
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
135
143
|
 
|
|
136
144
|
|
|
137
145
|
# Getting Started
|
|
@@ -152,12 +160,12 @@ These are all the available features of the SDK.
|
|
|
152
160
|
1
|
|
153
161
|
</td>
|
|
154
162
|
<td align="left">
|
|
155
|
-
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/
|
|
163
|
+
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/1_Authentication.md">
|
|
156
164
|
<code>Authentication</code>
|
|
157
165
|
</a>
|
|
158
166
|
</td>
|
|
159
167
|
<td align="left">
|
|
160
|
-
Manages user credentials between app sessions. Required if you would like to use <a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/
|
|
168
|
+
Manages user credentials between app sessions. Required if you would like to use <a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/2_Inbox.md"><code>Courier Inbox</code></a> and <a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/3_PushNotifications.md"><code>Push Notifications</code></a>.
|
|
161
169
|
</td>
|
|
162
170
|
</tr>
|
|
163
171
|
<tr width="600px">
|
|
@@ -165,7 +173,7 @@ These are all the available features of the SDK.
|
|
|
165
173
|
2
|
|
166
174
|
</td>
|
|
167
175
|
<td align="left">
|
|
168
|
-
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/
|
|
176
|
+
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/2_Inbox.md">
|
|
169
177
|
<code>Inbox</code>
|
|
170
178
|
</a>
|
|
171
179
|
</td>
|
|
@@ -178,7 +186,7 @@ These are all the available features of the SDK.
|
|
|
178
186
|
3
|
|
179
187
|
</td>
|
|
180
188
|
<td align="left">
|
|
181
|
-
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/
|
|
189
|
+
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/3_PushNotifications.md">
|
|
182
190
|
<code>Push Notifications</code>
|
|
183
191
|
</a>
|
|
184
192
|
</td>
|
|
@@ -191,7 +199,7 @@ These are all the available features of the SDK.
|
|
|
191
199
|
4
|
|
192
200
|
</td>
|
|
193
201
|
<td align="left">
|
|
194
|
-
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/
|
|
202
|
+
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/4_Preferences.md">
|
|
195
203
|
<code>Preferences</code>
|
|
196
204
|
</a>
|
|
197
205
|
</td>
|
|
@@ -204,7 +212,7 @@ These are all the available features of the SDK.
|
|
|
204
212
|
5
|
|
205
213
|
</td>
|
|
206
214
|
<td align="left">
|
|
207
|
-
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/
|
|
215
|
+
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/5_Client.md">
|
|
208
216
|
<code>CourierClient</code>
|
|
209
217
|
</a>
|
|
210
218
|
</td>
|
|
@@ -217,6 +225,12 @@ These are all the available features of the SDK.
|
|
|
217
225
|
|
|
218
226
|
 
|
|
219
227
|
|
|
228
|
+
# Expo
|
|
229
|
+
|
|
230
|
+
If you are using Expo, you should check out the [Expo Docs](https://github.com/trycourier/courier-react-native/blob/master/Docs/6_Expo.md) for all the details.
|
|
231
|
+
|
|
232
|
+
 
|
|
233
|
+
|
|
220
234
|
# Example Projects
|
|
221
235
|
|
|
222
236
|
Starter projects using this SDK.
|
package/android/build.gradle
CHANGED
|
@@ -110,7 +110,7 @@ dependencies {
|
|
|
110
110
|
implementation 'com.google.code.gson:gson:2.11.0'
|
|
111
111
|
|
|
112
112
|
// Courier Core SDK
|
|
113
|
-
api 'com.github.trycourier:courier-android:5.2.
|
|
113
|
+
api 'com.github.trycourier:courier-android:5.2.2'
|
|
114
114
|
api 'androidx.recyclerview:recyclerview:1.3.2'
|
|
115
115
|
|
|
116
116
|
}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
package com.courierreactnative
|
|
2
2
|
|
|
3
|
-
import android.annotation.SuppressLint
|
|
4
3
|
import android.content.Intent
|
|
5
4
|
import android.os.Bundle
|
|
6
5
|
import com.courier.android.Courier
|
|
7
|
-
import com.courier.android.utils.getLastDeliveredMessage
|
|
8
|
-
import com.courier.android.utils.pushNotification
|
|
9
6
|
import com.courier.android.utils.trackPushNotificationClick
|
|
10
7
|
import com.facebook.react.ReactActivity
|
|
11
|
-
import com.google.firebase.messaging.RemoteMessage
|
|
12
|
-
import org.json.JSONObject
|
|
13
8
|
|
|
14
9
|
open class CourierReactNativeActivity : ReactActivity() {
|
|
15
10
|
|
|
@@ -27,11 +22,6 @@ open class CourierReactNativeActivity : ReactActivity() {
|
|
|
27
22
|
// See if there is a pending click event
|
|
28
23
|
checkIntentForPushNotificationClick(intent)
|
|
29
24
|
|
|
30
|
-
// Handle delivered messages on the main thread
|
|
31
|
-
Courier.shared.getLastDeliveredMessage { message ->
|
|
32
|
-
postPushNotificationDelivered(message)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
25
|
}
|
|
36
26
|
|
|
37
27
|
override fun onNewIntent(intent: Intent?) {
|
|
@@ -40,25 +30,7 @@ open class CourierReactNativeActivity : ReactActivity() {
|
|
|
40
30
|
}
|
|
41
31
|
|
|
42
32
|
private fun checkIntentForPushNotificationClick(intent: Intent?) {
|
|
43
|
-
intent?.trackPushNotificationClick {
|
|
44
|
-
postPushNotificationClicked(message)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@SuppressLint("VisibleForTests")
|
|
49
|
-
private fun postPushNotificationDelivered(message: RemoteMessage) {
|
|
50
|
-
reactInstanceManager.currentReactContext?.sendEvent(
|
|
51
|
-
eventName = CourierEvents.Push.DELIVERED_EVENT,
|
|
52
|
-
value = JSONObject(message.pushNotification).toString()
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@SuppressLint("VisibleForTests")
|
|
57
|
-
private fun postPushNotificationClicked(message: RemoteMessage) {
|
|
58
|
-
reactInstanceManager.currentReactContext?.sendEvent(
|
|
59
|
-
eventName = CourierEvents.Push.CLICKED_EVENT,
|
|
60
|
-
value = JSONObject(message.pushNotification).toString()
|
|
61
|
-
)
|
|
33
|
+
intent?.trackPushNotificationClick {}
|
|
62
34
|
}
|
|
63
35
|
|
|
64
36
|
}
|
|
@@ -2,10 +2,14 @@ package com.courierreactnative
|
|
|
2
2
|
|
|
3
3
|
import android.content.Intent
|
|
4
4
|
import android.provider.Settings
|
|
5
|
+
import android.util.Log
|
|
5
6
|
import com.courier.android.Courier
|
|
7
|
+
import com.courier.android.models.CourierTrackingEvent.CLICKED
|
|
8
|
+
import com.courier.android.models.CourierTrackingEvent.DELIVERED
|
|
6
9
|
import com.courier.android.modules.isPushPermissionGranted
|
|
7
10
|
import com.courier.android.modules.requestNotificationPermission
|
|
8
11
|
import com.courier.android.utils.error
|
|
12
|
+
import com.courier.android.utils.onPushNotificationEvent
|
|
9
13
|
import com.courier.android.utils.pushNotification
|
|
10
14
|
import com.courier.android.utils.trackPushNotificationClick
|
|
11
15
|
import com.facebook.react.bridge.Promise
|
|
@@ -16,6 +20,19 @@ import org.json.JSONObject
|
|
|
16
20
|
|
|
17
21
|
class CourierSystemModule(reactContext: ReactApplicationContext): ReactNativeModule(tag = "System Error", name = "CourierSystemModule", reactContext = reactContext) {
|
|
18
22
|
|
|
23
|
+
init {
|
|
24
|
+
|
|
25
|
+
// Handle delivered messages on the main thread
|
|
26
|
+
Courier.shared.onPushNotificationEvent { event ->
|
|
27
|
+
when (event.trackingEvent) {
|
|
28
|
+
CLICKED -> postPushNotificationJavascriptEvent(CourierEvents.Push.CLICKED_EVENT, event.remoteMessage)
|
|
29
|
+
DELIVERED -> postPushNotificationJavascriptEvent(CourierEvents.Push.DELIVERED_EVENT, event.remoteMessage)
|
|
30
|
+
else -> Log.w("CourierSystemModule", "Unknown tracking event: ${event.trackingEvent}")
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
19
36
|
@ReactMethod
|
|
20
37
|
fun addListener(type: String?) {
|
|
21
38
|
// Keep: Required for RN built in Event Emitter Calls.
|
|
@@ -35,13 +52,13 @@ class CourierSystemModule(reactContext: ReactApplicationContext): ReactNativeMod
|
|
|
35
52
|
|
|
36
53
|
private fun checkIntentForPushNotificationClick(intent: Intent?) {
|
|
37
54
|
intent?.trackPushNotificationClick { message ->
|
|
38
|
-
|
|
55
|
+
postPushNotificationJavascriptEvent(CourierEvents.Push.CLICKED_EVENT, message)
|
|
39
56
|
}
|
|
40
57
|
}
|
|
41
58
|
|
|
42
|
-
private fun
|
|
59
|
+
private fun postPushNotificationJavascriptEvent(eventName: String, message: RemoteMessage) {
|
|
43
60
|
reactApplicationContext.sendEvent(
|
|
44
|
-
eventName =
|
|
61
|
+
eventName = eventName,
|
|
45
62
|
value = JSONObject(message.pushNotification).toString()
|
|
46
63
|
)
|
|
47
64
|
}
|
|
@@ -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.3")
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
if (self) {
|
|
27
27
|
|
|
28
28
|
// Set the user agent
|
|
29
|
-
Courier.agent = [CourierAgent reactNativeIOS:@"5.5.
|
|
29
|
+
Courier.agent = [CourierAgent reactNativeIOS:@"5.5.3"];
|
|
30
30
|
|
|
31
31
|
// Register for remote notifications
|
|
32
32
|
UIApplication *app = [UIApplication sharedApplication];
|
|
@@ -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.3")
|
|
18
18
|
|
|
19
19
|
}
|
|
20
20
|
|