@trycourier/courier-react-native 5.5.2 → 5.5.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 CHANGED
@@ -118,12 +118,11 @@ Your app must support at least gradle `8.4`
118
118
 
119
119
   
120
120
 
121
- ### 3. Extend the `CourierReactNativeActivity`
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/Authentication.md">
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/Inbox.md"><code>Courier Inbox</code></a> and <a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/PushNotifications.md"><code>Push Notifications</code></a>.
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/Inbox.md">
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/PushNotifications.md">
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/Preferences.md">
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/Client.md">
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
  &emsp;
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
+ &emsp;
233
+
220
234
  # Example Projects
221
235
 
222
236
  Starter projects using this SDK.
@@ -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.0'
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 { message ->
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
+ // Listen to push notification events
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
- postPushNotificationClicked(message)
55
+ postPushNotificationJavascriptEvent(CourierEvents.Push.CLICKED_EVENT, message)
39
56
  }
40
57
  }
41
58
 
42
- private fun postPushNotificationClicked(message: RemoteMessage) {
59
+ private fun postPushNotificationJavascriptEvent(eventName: String, message: RemoteMessage) {
43
60
  reactApplicationContext.sendEvent(
44
- eventName = CourierEvents.Push.CLICKED_EVENT,
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.2")
18
+ val COURIER_AGENT = CourierAgent.ReactNativeAndroid(version = "5.5.4")
19
19
  }
20
20
 
21
21
  internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
@@ -2,7 +2,7 @@
2
2
  // CourierReactNativeDelegate.m
3
3
  // courier-react-native
4
4
  //
5
- // Created by Michael Miller on 10/7/22.
5
+ // Created by https://github.com/mikemilla on 10/7/22.
6
6
  //
7
7
 
8
8
  @import Courier_iOS;
@@ -12,21 +12,20 @@
12
12
 
13
13
  @interface CourierReactNativeDelegate ()
14
14
 
15
- @property (nonatomic, copy) NSString *iosForegroundNotificationPresentationOptions;
16
15
  @property (nonatomic, assign) UNNotificationPresentationOptions notificationPresentationOptions;
17
16
 
18
17
  @end
19
18
 
20
19
  @implementation CourierReactNativeDelegate
21
20
 
22
- - (id) init {
23
-
21
+ static NSString *const CourierForegroundOptionsDidChangeNotification = @"iosForegroundNotificationPresentationOptions";
22
+
23
+ - (id)init {
24
24
  self = [super init];
25
25
 
26
26
  if (self) {
27
-
28
27
  // Set the user agent
29
- Courier.agent = [CourierAgent reactNativeIOS:@"5.5.2"];
28
+ Courier.agent = [CourierAgent reactNativeIOS:@"5.5.4"];
30
29
 
31
30
  // Register for remote notifications
32
31
  UIApplication *app = [UIApplication sharedApplication];
@@ -39,28 +38,27 @@
39
38
  [[NSNotificationCenter defaultCenter]
40
39
  addObserver:self
41
40
  selector:@selector(notificationPresentationOptionsUpdate:)
42
- name:_iosForegroundNotificationPresentationOptions
41
+ name:CourierForegroundOptionsDidChangeNotification
43
42
  object:nil
44
43
  ];
45
-
46
44
  }
47
45
 
48
- return(self);
49
-
46
+ return self;
50
47
  }
51
48
 
52
- - (void) notificationPresentationOptionsUpdate:(NSNotification *) notification
49
+ - (void)notificationPresentationOptionsUpdate:(NSNotification *)notification
53
50
  {
54
- if ([[notification name] isEqualToString:_iosForegroundNotificationPresentationOptions])
51
+ if ([[notification name] isEqualToString:CourierForegroundOptionsDidChangeNotification])
55
52
  {
56
53
  NSDictionary *userInfo = notification.userInfo;
57
- _notificationPresentationOptions = ((NSNumber *) [userInfo objectForKey:@"options"]).unsignedIntegerValue;
54
+ self.notificationPresentationOptions = ((NSNumber *)[userInfo objectForKey:@"options"]).unsignedIntegerValue;
58
55
  }
59
56
  }
60
57
 
61
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
58
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
59
+ willPresentNotification:(UNNotification *)notification
60
+ withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
62
61
  {
63
-
64
62
  UNNotificationContent *content = notification.request.content;
65
63
  NSDictionary *message = content.userInfo;
66
64
 
@@ -71,19 +69,16 @@
71
69
  }];
72
70
 
73
71
  dispatch_async(dispatch_get_main_queue(), ^{
74
-
75
72
  NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
76
73
  [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationDelivered" object:nil userInfo:pushNotification];
77
-
78
- completionHandler(self->_notificationPresentationOptions);
79
-
74
+ completionHandler(self.notificationPresentationOptions);
80
75
  });
81
-
82
76
  }
83
77
 
84
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
78
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
79
+ didReceiveNotificationResponse:(UNNotificationResponse *)response
80
+ withCompletionHandler:(void (^)(void))completionHandler
85
81
  {
86
-
87
82
  UNNotificationContent *content = response.notification.request.content;
88
83
  NSDictionary *message = content.userInfo;
89
84
 
@@ -94,22 +89,20 @@
94
89
  }];
95
90
 
96
91
  dispatch_async(dispatch_get_main_queue(), ^{
97
-
98
92
  NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
99
93
  [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked" object:nil userInfo:pushNotification];
100
-
101
94
  completionHandler();
102
-
103
95
  });
104
-
105
96
  }
106
97
 
107
- - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
98
+ - (void)application:(UIApplication *)application
99
+ didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
108
100
  {
109
- NSLog(@"Failed to rgister for remote notification token: %@", error.localizedDescription);
101
+ NSLog(@"Failed to register for remote notification token: %@", error.localizedDescription);
110
102
  }
111
103
 
112
- - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
104
+ - (void)application:(UIApplication *)application
105
+ didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
113
106
  {
114
107
  [Courier setAPNSToken:deviceToken];
115
108
  }
@@ -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.2")
17
+ Courier.agent = CourierAgent.reactNativeIOS("5.5.4")
18
18
 
19
19
  }
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react-native",
3
- "version": "5.5.2",
3
+ "version": "5.5.4",
4
4
  "description": "Inbox, Push Notifications, and Preferences for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",