@trycourier/courier-react-native 0.1.0 → 1.0.0

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
@@ -1,7 +1,9 @@
1
1
  # Courier React Native Overview
2
2
 
3
3
  ```ts
4
- await Courier.setIsDebugging(!isDebugging);
4
+ import Courier, { CourierProvider } from '@trycourier/courier-react-native'
5
+
6
+ await Courier.setIsDebugging(true);
5
7
 
6
8
  const userId = await Courier.userId;
7
9
 
@@ -17,10 +19,9 @@ await Courier.iOSForegroundPresentationOptions({
17
19
  });
18
20
 
19
21
  const currentPermissionStatus = await Courier.notificationPermissionStatus;
20
- const requestNotificationPermission =
21
- await Courier.requestNotificationPermission();
22
+ const requestNotificationPermission = await Courier.requestNotificationPermission();
22
23
 
23
- await Courier.shared.setFcmToken('asdf...');
24
+ await Courier.setFcmToken('asdf...');
24
25
 
25
26
  const fcmToken = await Courier.fcmToken;
26
27
  const apnsToken = await Courier.apnsToken;
@@ -46,15 +47,11 @@ const messageId = await Courier.sendPush({
46
47
 
47
48
  # Requirements & Support
48
49
 
49
- | Operating System | Minimum SDK | Compile Target SDK |
50
- | :--------------- | ----------: | -----------------: |
51
- | `iOS` | `13` | — |
52
- | `Android` | `21` | `32` |
53
50
 
54
- | Push Provider | Supported Platforms |
55
- | :--------------------------------------- | ------------------: |
56
- | `APNS (Apple Push Notification Service)` | `iOS` |
57
- | `FCM (Firebase Cloud Messaging)` | `Android` |
51
+ | Operating System | Min SDK | Compile SDK | Firebase Cloud Messaging | Apple Push Notification Service | Expo | OneSignal | Courier Inbox | Courier Toast |
52
+ | :-- | --: | --: | --: | --: | --: | --: | --: | --: |
53
+ | `iOS` | `13` | — | ❌ | ✅ | | ❌ | ❌ | ❌ |
54
+ | `Android` | `21` | `32` | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
58
55
 
59
56
  > Most of this SDK depends on a Courier account: [`Create a Courier account here`](https://app.courier.com/signup)
60
57
 
@@ -64,17 +61,12 @@ const messageId = await Courier.sendPush({
64
61
 
65
62
  > Link to [`Example App`](https://github.com/trycourier/courier-react-native/tree/master/example)
66
63
 
67
- - [Courier React Native Overview](#courier-react-native-overview)
68
- - [Requirements & Support](#requirements--support)
69
- - [**Installation**](#installation)
70
- - [**1. Install the package**](#1-install-the-package)
71
- - [**2. iOS Setup**](#2-ios-setup)
72
- - [**Add the Notification Service Extension (Recommended)**](#add-the-notification-service-extension-recommended)
73
- - [**3. Android Setup**](#3-android-setup)
74
- - [**4. Configure Push Provider**](#4-configure-push-provider)
75
- - [**5. Managing User State**](#5-managing-user-state)
76
- - [**Going to Production**](#going-to-production)
77
- - [**Share feedback with Courier**](#share-feedback-with-courier)
64
+ 1. [`Install the package`](#1-install-the-package)
65
+ 2. [`iOS Setup`](#2-ios-setup)
66
+ 3. [`Android Setup`](#3-android-setup)
67
+ 4. [`Configure Push Provider`](#4-configure-push-provider)
68
+ 5. [`Managing User State`](#5-managing-user-state)
69
+ 6. [`Going to Production`](#going-to-production)
78
70
 
79
71
   
80
72
 
@@ -100,20 +92,40 @@ yarn add @trycourier/courier-react-native
100
92
 
101
93
  > If you don't need push notification support on iOS, you can skip this step.
102
94
 
103
- https://user-images.githubusercontent.com/6370613/198094477-40f22b1e-b3ad-4029-9120-0eee22de02e0.mov
95
+ https://user-images.githubusercontent.com/6370613/199279392-1b376929-4a03-4acd-9d00-d170085d9791.mov
96
+
97
+ ### Written Tutorial 👇
98
+
99
+ 1. Open your iOS project and increase the min SDK target to iOS 13.0+
100
+ 2. Open your `Podfile` and increase the platform:
101
+
102
+ ```
103
+ ..
104
+ platform :ios, '13'
105
+ ..
106
+ ```
104
107
 
105
- 1. From your project's root directory, run: `cd ios && pod update`
106
- 2. Open your iOS project and increase the min SDK target to iOS 13.0+
107
- 3. Change your `AppDelegate` to extend the `CourierReactNativeDelegate`
108
- - This automatically syncs APNS tokens to Courier
108
+ 3. From your React Native project's root directory, run: `cd ios && pod update`
109
+ 4. In Xcode, change your `AppDelegate.h` to use the snippet below:
110
+ - This automatically syncs APNS tokens to Courier token management
109
111
  - Allows the React Native SDK to handle when push notifications are delivered and clicked
112
+
113
+ ```objective-c
114
+ #import <courier-react-native/CourierReactNativeDelegate.h>
115
+
116
+ @interface AppDelegate : CourierReactNativeDelegate
117
+ @end
118
+ ```
119
+
110
120
  4. Enable the "Push Notifications" capability
111
121
 
112
122
  ### **Add the Notification Service Extension (Recommended)**
113
123
 
114
124
  To make sure Courier can track when a notification is delivered to the device, you need to add a Notification Service Extension. Here is how to add one.
115
125
 
116
- https://user-images.githubusercontent.com/6370613/198336479-45aeec9e-0c94-4c29-b132-ea8c777b9da1.mov
126
+ https://user-images.githubusercontent.com/6370613/199331562-5d16e02f-2878-4f60-bbe2-075ae119c6bc.mov
127
+
128
+ ### Written Tutorial 👇
117
129
 
118
130
  1. Download and Unzip the Courier Notification Service Extension: [`CourierNotificationServiceTemplate.zip`](https://github.com/trycourier/courier-notification-service-extension-template/archive/refs/heads/main.zip)
119
131
  2. Open the folder in terminal and run `sh make_template.sh`
@@ -128,12 +140,11 @@ https://user-images.githubusercontent.com/6370613/198336479-45aeec9e-0c94-4c29-b
128
140
 
129
141
  ```
130
142
  target 'CourierService' do
131
- use_frameworks!
132
143
  pod 'Courier-iOS'
133
144
  end
134
145
  ```
135
146
 
136
- 1. From the root of your React Native app, run: `cd ios && pod install`
147
+ 8. From the root of your React Native app, run: `cd ios && pod install`
137
148
 
138
149
  &emsp;
139
150
 
@@ -141,75 +152,109 @@ end
141
152
 
142
153
  > If you don't need push notification support on Android, you can skip this step.
143
154
 
144
- https://user-images.githubusercontent.com/6370613/198111372-09a29aba-6507-4cf7-a59d-87e8df2ba492.mov
155
+ https://user-images.githubusercontent.com/6370613/199335432-aa52028a-f7ae-48bb-abec-427795baa6f4.mov
156
+
157
+ ### Written Tutorial 👇
145
158
 
146
159
  1. Open Android project
147
- 2. Add support for Jitpack to `android/build.gradle`
148
- - This is needed because the Courier Android SDK is hosted using Jitpack
149
- - Maven support will be coming later
160
+ 2. Register your app in Firebase and download your `google-services.json` file
161
+ 3. Add the `google-services.json` file to your `yourApp/app/src` directory
162
+ 4. Make sure your `yourApp/android/build.gradle` file supports Jitpack:
150
163
 
151
- ```gradle
164
+ ```groovy
152
165
  allprojects {
153
166
  repositories {
154
- google()
155
- mavenCentral()
156
- maven { url 'https://jitpack.io' } // Add this line
167
+ ..
168
+ maven { url 'https://www.jitpack.io' } // This line is needed
157
169
  }
158
170
  }
159
171
  ```
160
172
 
161
- 3. Update your `app/build.gradle` to support the min and compile SDKs
162
- - `minSdkVersion 21`
163
- - `compileSdkVersion 33`
164
- 4. Run Gradle sync
165
- 5. add the `google-services` plugin as a dependency inside of your `/android/build.gradle` file:
173
+ 3. Update your `yourApp/android/build.gradle` to support the following SDK versions
174
+ - This is needed to support newer Android Notification APIs
175
+
176
+ ```groovy
177
+ buildscript {
178
+ ext {
179
+ buildToolsVersion = "32.0.0"
180
+ minSdkVersion = 21
181
+ compileSdkVersion = 32
182
+ targetSdkVersion = 32
183
+ ..
184
+ }
185
+ ..
186
+ }
187
+ ```
188
+
189
+ 4. Add the `google-services` dependency to your `yourApp/android/build.gradle` file:
166
190
 
167
191
  ```groovy
168
192
  buildscript {
169
193
  dependencies {
170
- // ... other dependencies
171
- classpath 'com.google.gms:google-services:4.3.14'
172
- // Add me --- /\
194
+ ..
195
+ classpath("com.google.gms:google-services:4.3.14") // Add this line
173
196
  }
174
197
  }
175
198
  ```
176
199
 
177
- 6. execute the plugin by adding the following to your `/android/app/build.gradle` file:
200
+ 5. Add this following line to the top of your `/android/app/build.gradle` file:
178
201
 
179
202
  ```groovy
180
- apply plugin: 'com.android.application'
181
- apply plugin: 'com.google.gms.google-services' // <- Add this line
203
+ apply plugin: "com.android.application"
204
+ apply plugin: "com.google.gms.google-services" // Add this line
182
205
  ```
183
206
 
184
- 7. Change your `MainActivity` to extend the `CourierReactNativeActivity`
207
+ 6. Run Gradle Sync
208
+
209
+ ### **Update Activity and Register Service**
210
+
211
+ https://user-images.githubusercontent.com/6370613/199335233-0880209b-5aec-4584-9726-eaa1077bf80d.mov
212
+
213
+ ### Written Tutorial 👇
214
+
215
+ 1. Change your `MainActivity` to extend the `CourierReactNativeActivity`
185
216
  - This allows Courier to handle when push notifications are delivered and clicked
186
- 8. Setup a new Notification Service by creating a new file and pasting the code below in it
187
- - This allows you to present a notification to your user when a new notification arrives
217
+ 2. Setup a new Notification Service by creating a new java file and paste the code below in it
218
+ - This allows you to present a notification to your user when a new notification arrives and will automatically sync new fcm tokens to Courier token management
188
219
 
189
220
  ```java
190
- import androidx.annotation.NonNull;
221
+ // Your project import
191
222
 
223
+ import android.annotation.SuppressLint;
224
+ import androidx.annotation.NonNull;
192
225
  import com.courier.android.notifications.RemoteMessageExtensionsKt;
193
226
  import com.courier.android.service.CourierService;
194
227
  import com.google.firebase.messaging.RemoteMessage;
195
228
 
196
- public class YourNotificationService extends CourierService {
197
- @Override
198
- public void showNotification(@NonNull RemoteMessage message) {
199
- super.showNotification(message);
200
-
201
- RemoteMessageExtensionsKt.presentNotification(
202
- message,
203
- this,
204
- MainActivity.class,
205
- android.R.drawable.ic_dialog_info,
206
- "Notification Service"
207
- );
208
- }
229
+ // This is safe. `CourierService` will automatically handle token refreshes.
230
+ @SuppressLint("MissingFirebaseInstanceTokenRefresh")
231
+ public class YourExampleService extends CourierService {
232
+
233
+ @Override
234
+ public void showNotification(@NonNull RemoteMessage message) {
235
+ super.showNotification(message);
236
+
237
+ // TODO: This is where you will customize the notification that is shown to your users
238
+ // The function below is used to get started quickly.
239
+ // You likely do not want to use `message.presentNotification(...)`
240
+ // For React Native, you likely do not want to change RemoteMessageExtensionsKt.presentNotification.handlingClass
241
+ // More information on how to customize an Android notification here:
242
+ // https://developer.android.com/develop/ui/views/notifications/build-notification
243
+
244
+ RemoteMessageExtensionsKt.presentNotification(
245
+ message,
246
+ this,
247
+ MainActivity.class,
248
+ android.R.drawable.ic_dialog_info,
249
+ "Notification Service"
250
+ );
251
+
252
+ }
253
+
209
254
  }
210
255
  ```
211
256
 
212
- 7. Add the Notification Service entry in your `AndroidManifest.xml` file
257
+ 3. Add the Notification Service entry in your `AndroidManifest.xml` file
213
258
 
214
259
  ```xml
215
260
  <manifest>
@@ -221,7 +266,7 @@ public class YourNotificationService extends CourierService {
221
266
 
222
267
  // Add this 👇
223
268
  <service
224
- android:name=".YourNotificationService"
269
+ android:name=".YourExampleService"
225
270
  android:exported="false">
226
271
  <intent-filter>
227
272
  <action android:name="com.google.firebase.MESSAGING_EVENT" />
@@ -243,8 +288,8 @@ public class YourNotificationService extends CourierService {
243
288
 
244
289
  To get push notification to appear in your app, add support for the provider you would like to use:
245
290
 
246
- - [`APNS (Apple Push Notification Service)`](https://www.courier.com/docs/guides/providers/push/apple-push-notification)
247
- - [`FCM (Firebase Cloud Messaging)`](https://www.courier.com/docs/guides/providers/push/firebase-fcm/)
291
+ - [`APNS (Apple Push Notification Service)`](https://app.courier.com/channels/apn)
292
+ - [`FCM (Firebase Cloud Messaging)`](https://app.courier.com/channels/firebase-fcm)
248
293
 
249
294
  &emsp;
250
295
 
@@ -262,12 +307,12 @@ Place these functions where you normally manage your user's state:
262
307
  ```dart
263
308
  // Saves accessToken and userId to native level local storage
264
309
  // This will persist between app sessions
265
- await Courier.shared.signIn(
266
- accessToken: accessToken,
267
- userId: userId,
268
- );
310
+ await Courier.signIn({
311
+ accessToken: accessToken,
312
+ userId: userId,
313
+ });
269
314
 
270
- await Courier.shared.signOut();
315
+ await Courier.signOut();
271
316
  ```
272
317
 
273
318
  If you followed the steps above:
@@ -303,47 +348,48 @@ FirebaseMessaging.instance.onTokenRefresh.listen((fcmToken) {
303
348
  Courier allows you to send a push notification directly from the SDK to a user id. No tokens juggling or backend needed!
304
349
 
305
350
  ```typescript
306
- const notificationPermission = await Courier.notificationPermissionStatus;;
307
- print(notificationPermission);
351
+ const notificationPermission = await Courier.notificationPermissionStatus;
352
+ console.log(notificationPermission);
308
353
 
309
354
  // Notification permissions must be `authorized` on iOS to receive pushes
310
355
 
311
356
  const requestedNotificationPermission = await Courier.requestNotificationPermission();
312
- print(requestedNotificationPermission);
357
+ console.log(requestedNotificationPermission);
313
358
 
314
359
  // This is how iOS will show the notification when the app is in the foreground
315
360
  // Passing [] will not present anything
316
- // `Courier.shared.onPushNotificationDelivered` will still get called
361
+ // `onPushNotificationDelivered` will still get called
317
362
  await Courier.iOSForegroundPresentationOptions({
318
363
  options: ['badge', 'banner', 'list', 'sound'],
319
364
  });
320
365
 
321
366
 
322
- // the function returns an unsubscribe function
323
- // call the function to stop listening to notifications
367
+ // This function returns an unsubscribe function
368
+ // Call `unsibscribe();` to stop listening to notifications
324
369
  // Recommended to call the function while component mounts and unsubscribe when the component unmounts
325
370
  const unsubscribe = Courier.registerPushNotificationListeners({
326
371
 
327
372
  // Will be called if the app is in the foreground and a push notification arrives
328
373
  onPushNotificationClicked(push) {
329
- ...
374
+ console.log(push.title)
330
375
  },
331
376
 
332
377
  // Will be called when a user clicks a push notification
333
378
  onPushNotificationDelivered(push) {
334
- ...
335
- },
379
+ console.log(push.title)
380
+ }
381
+
336
382
  });
337
383
 
338
384
  // Sends a test push
339
- const messageId = await Courier.shared.sendPush(
340
- authKey: 'a_courier_auth_key_that_should_only_be_used_for_testing',
341
- userId: 'example_user',
342
- title: 'Chirp Chrip!',
343
- body: 'Hello from Courier 🐣',
344
- isProduction: false, // This only affects APNS pushes. false == sandbox / true == production
345
- providers: [CourierProvider.APNS, CourierProvider.FCM],
346
- );
385
+ const messageId = await Courier.sendPush({
386
+ authKey: 'your_courier_auth_key_that_should_only_be_used_for_testing',
387
+ userId: 'example_user',
388
+ title: 'Chirp Chrip!',
389
+ body: 'Hello from Courier 🐣',
390
+ isProduction: false, // This only affects APNS pushes. false == sandbox / true == production
391
+ providers: [CourierProvider.APNS, CourierProvider.FCM],
392
+ });
347
393
  ```
348
394
 
349
395
  &emsp;
@@ -367,8 +413,7 @@ curl --request POST \
367
413
  }'
368
414
  ```
369
415
 
370
- Or generate one here:
371
- [`Issue Courier Access Token`](https://www.courier.com/docs/reference/auth/issue-token/)
416
+ Or generate one here: [`Issue Courier Access Token`](https://www.courier.com/docs/reference/auth/issue-token/)
372
417
 
373
418
  > This request to issue a token should likely exist in a separate endpoint served on your backend.
374
419
 
@@ -379,4 +424,4 @@ Or generate one here:
379
424
  We want to make this the best SDK for managing notifications! Have an idea or feedback about our SDKs? Here are some links to contact us:
380
425
 
381
426
  - [Courier Feedback](https://feedback.courier.com/)
382
- - [Courier React native Issues](https://github.com/trycourier/courier-react-native/issues)
427
+ - [Courier React Native Issues](https://github.com/trycourier/courier-react-native/issues)
@@ -184,6 +184,16 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
184
184
  .emit(eventName, params)
185
185
  }
186
186
 
187
+ @ReactMethod
188
+ fun addListener(eventName: String?) {
189
+ // Empty
190
+ }
191
+
192
+ @ReactMethod
193
+ fun removeListeners(count: Int?) {
194
+ // Empty
195
+ }
196
+
187
197
  private fun ReadableArray.toCourierProviders(): List<CourierProvider> {
188
198
  val providers: MutableList<CourierProvider> = mutableListOf()
189
199
  for (provider in toArrayList()) {
@@ -7,7 +7,9 @@ class CourierReactNative: RCTEventEmitter {
7
7
  internal static let COURIER_PUSH_NOTIFICATION_CLICKED_EVENT = "pushNotificationClicked"
8
8
  internal static let COURIER_PUSH_NOTIFICATION_DELIVERED_EVENT = "pushNotificationDelivered"
9
9
  private static let COURIER_PUSH_NOTIFICATION_DEBUG_LOG_EVENT = "courierDebugEvent"
10
-
10
+
11
+ private var isDebugListenerRegistered = false
12
+
11
13
  private var lastClickedMessage: [AnyHashable: Any]? = nil
12
14
  private var notificationCenter: NotificationCenter {
13
15
  get {
@@ -24,12 +26,7 @@ class CourierReactNative: RCTEventEmitter {
24
26
 
25
27
  // Attach the listeners
26
28
  attachObservers()
27
-
28
- // Send notification to react native side
29
- Courier.shared.logListener = {log in
30
- self.sendEvent(withName: CourierReactNative.COURIER_PUSH_NOTIFICATION_DEBUG_LOG_EVENT, body: log)
31
- }
32
-
29
+
33
30
  }
34
31
 
35
32
  private func attachObservers() {
@@ -220,10 +217,19 @@ class CourierReactNative: RCTEventEmitter {
220
217
  }
221
218
 
222
219
  @objc(setDebugMode: withResolver: withRejecter:)
223
- func setDebugMode(isDebugging: Bool,resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock){
220
+ func setDebugMode(isDebugging: Bool,resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
221
+
222
+ // Send notification to react native side
223
+ if (isDebugging && !isDebugListenerRegistered) {
224
+ isDebugListenerRegistered = true
225
+ Courier.shared.logListener = { log in
226
+ self.sendEvent(withName: CourierReactNative.COURIER_PUSH_NOTIFICATION_DEBUG_LOG_EVENT, body: log)
227
+ }
228
+ }
229
+
224
230
  Courier.shared.isDebugging = isDebugging
225
- print("setIsDebugging", isDebugging);
226
231
  resolve(Courier.shared.isDebugging)
232
+
227
233
  }
228
234
 
229
235
  override func supportedEvents() -> [String]! {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react-native",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "description": "test",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",