@trycourier/courier-react-native 1.0.9 → 2.0.0-beta0
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/LICENSE +1 -1
- package/README.md +16 -412
- package/android/build.gradle +48 -83
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +10 -10
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +146 -137
- package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +1 -3
- package/android/src/main/java/com/courierreactnative/CourierReactNativeViewManager.kt +43 -0
- package/courier-react-native.podspec +12 -4
- package/ios/CourierReactNative-Bridging-Header.h +0 -1
- package/ios/CourierReactNative.xcodeproj/project.pbxproj +4 -4
- package/ios/CourierReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/CourierReactNativeModule.m +48 -0
- package/ios/{CourierReactNative.swift → CourierReactNativeModule.swift} +165 -45
- package/ios/CourierReactNativeViewManager.m +15 -0
- package/ios/CourierReactNativeViewManager.swift +348 -0
- package/lib/commonjs/index.js +68 -213
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/CourierInboxListener.js +26 -0
- package/lib/commonjs/models/CourierInboxListener.js.map +1 -0
- package/lib/commonjs/models/CourierInboxTheme.js +2 -0
- package/lib/commonjs/models/CourierInboxTheme.js.map +1 -0
- package/lib/commonjs/models/InboxAction.js +2 -0
- package/lib/commonjs/models/InboxAction.js.map +1 -0
- package/lib/commonjs/models/InboxMessage.js +6 -0
- package/lib/commonjs/models/InboxMessage.js.map +1 -0
- package/lib/commonjs/views/CourierInboxView.js +53 -0
- package/lib/commonjs/views/CourierInboxView.js.map +1 -0
- package/lib/module/index.js +62 -212
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/CourierInboxListener.js +18 -0
- package/lib/module/models/CourierInboxListener.js.map +1 -0
- package/lib/module/models/CourierInboxTheme.js +2 -0
- package/lib/module/models/CourierInboxTheme.js.map +1 -0
- package/lib/module/models/InboxAction.js +2 -0
- package/lib/module/models/InboxAction.js.map +1 -0
- package/lib/module/models/InboxMessage.js +2 -0
- package/lib/module/models/InboxMessage.js.map +1 -0
- package/lib/module/views/CourierInboxView.js +45 -0
- package/lib/module/views/CourierInboxView.js.map +1 -0
- package/lib/typescript/index.d.ts +34 -92
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/models/CourierInboxListener.d.ts +9 -0
- package/lib/typescript/models/CourierInboxListener.d.ts.map +1 -0
- package/lib/typescript/models/CourierInboxTheme.d.ts +34 -0
- package/lib/typescript/models/CourierInboxTheme.d.ts.map +1 -0
- package/lib/typescript/models/InboxAction.d.ts +8 -0
- package/lib/typescript/models/InboxAction.d.ts.map +1 -0
- package/lib/typescript/models/InboxMessage.d.ts +18 -0
- package/lib/typescript/models/InboxMessage.d.ts.map +1 -0
- package/lib/typescript/views/CourierInboxView.d.ts +16 -0
- package/lib/typescript/views/CourierInboxView.d.ts.map +1 -0
- package/package.json +61 -44
- package/src/index.tsx +188 -0
- package/src/models/CourierInboxListener.tsx +25 -0
- package/src/models/CourierInboxTheme.tsx +30 -0
- package/src/models/InboxAction.tsx +5 -0
- package/src/models/InboxMessage.tsx +16 -0
- package/src/views/CourierInboxView.tsx +85 -0
- package/android/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/compiler.xml +0 -6
- package/android/.idea/gradle.xml +0 -17
- package/android/.idea/jarRepositories.xml +0 -35
- package/android/.idea/misc.xml +0 -10
- package/android/.idea/vcs.xml +0 -6
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradlew +0 -185
- package/android/gradlew.bat +0 -89
- package/android/local.properties +0 -8
- package/android/src/main/java/com/courierreactnative/NotificationPermissionStatus.kt +0 -6
- package/ios/CourierReactNative.m +0 -52
- package/ios/CourierReactNativeDelegate.h +0 -20
- package/ios/CourierReactNativeDelegate.m +0 -125
- package/src/index.ts +0 -337
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2023 mikemilla
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
|
6
6
|
in the Software without restriction, including without limitation the rights
|
package/README.md
CHANGED
|
@@ -1,427 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# courier-react-native
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
import Courier, { CourierProvider } from '@trycourier/courier-react-native';
|
|
3
|
+
Inbox & Push Notifications for iOS
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
## Installation
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
await Courier.signIn({
|
|
11
|
-
accessToken: 'asdf...',
|
|
12
|
-
userId: 'example_user_id',
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
await Courier.signOut();
|
|
16
|
-
|
|
17
|
-
await Courier.iOSForegroundPresentationOptions({
|
|
18
|
-
options: ['badge', 'banner', 'list', 'sound'],
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const currentPermissionStatus = await Courier.notificationPermissionStatus;
|
|
22
|
-
const requestNotificationPermission =
|
|
23
|
-
await Courier.requestNotificationPermission();
|
|
24
|
-
|
|
25
|
-
await Courier.setFcmToken('asdf...');
|
|
26
|
-
|
|
27
|
-
const fcmToken = await Courier.fcmToken;
|
|
28
|
-
const apnsToken = await Courier.apnsToken;
|
|
29
|
-
|
|
30
|
-
const unsubscribe = Courier.registerPushNotificationListeners({
|
|
31
|
-
onPushNotificationClicked(push) {
|
|
32
|
-
console.log(push);
|
|
33
|
-
},
|
|
34
|
-
onPushNotificationDelivered(push) {
|
|
35
|
-
console.log(push);
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const messageId = await Courier.sendPush({
|
|
40
|
-
authKey: 'asdf...',
|
|
41
|
-
userId: 'example_user_id',
|
|
42
|
-
title: 'Hey! 👋',
|
|
43
|
-
body: 'Courier is awesome!!',
|
|
44
|
-
providers: [CourierProvider.APNS, CourierProvider.FCM],
|
|
45
|
-
});
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
 
|
|
49
|
-
|
|
50
|
-
# Requirements & Support
|
|
51
|
-
|
|
52
|
-
| Operating System | Min SDK | Compile SDK | Firebase Cloud Messaging | Apple Push Notification Service | Expo | OneSignal | Courier Inbox | Courier Toast |
|
|
53
|
-
| :--------------- | ------: | ----------: | -----------------------: | ------------------------------: | ---: | --------: | ------------: | ------------: |
|
|
54
|
-
| `iOS` | `13` | — | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
55
|
-
| `Android` | `21` | `32` | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
56
|
-
|
|
57
|
-
> Most of this SDK depends on a Courier account: [`Create a Courier account here`](https://app.courier.com/signup)
|
|
58
|
-
|
|
59
|
-
> Testing push notifications requires a physical device. Simulators will not work.
|
|
60
|
-
|
|
61
|
-
 
|
|
62
|
-
|
|
63
|
-
# **Installation**
|
|
64
|
-
|
|
65
|
-
> Link to [`Example App`](https://github.com/trycourier/courier-react-native/tree/master/example)
|
|
66
|
-
|
|
67
|
-
1. [`Install the package`](#1-install-the-package)
|
|
68
|
-
2. [`iOS Setup`](#2-ios-setup)
|
|
69
|
-
3. [`Android Setup`](#3-android-setup)
|
|
70
|
-
4. [`Configure Push Provider`](#4-configure-push-provider)
|
|
71
|
-
5. [`Managing User State`](#5-managing-user-state)
|
|
72
|
-
6. [`Going to Production`](#going-to-production)
|
|
73
|
-
|
|
74
|
-
 
|
|
75
|
-
|
|
76
|
-
## **1. Install the package**
|
|
77
|
-
|
|
78
|
-
Run the following command at your project's root directory:
|
|
79
|
-
|
|
80
|
-
using npm:
|
|
81
|
-
|
|
82
|
-
```
|
|
83
|
-
npm install @trycourier/courier-react-native
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
using yarn:
|
|
87
|
-
|
|
88
|
-
```
|
|
89
|
-
yarn add @trycourier/courier-react-native
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
 
|
|
93
|
-
|
|
94
|
-
## **2. iOS Setup**
|
|
95
|
-
|
|
96
|
-
> If you don't need push notification support on iOS, you can skip this step.
|
|
97
|
-
|
|
98
|
-
https://user-images.githubusercontent.com/6370613/199279392-1b376929-4a03-4acd-9d00-d170085d9791.mov
|
|
99
|
-
|
|
100
|
-
### Written Tutorial 👇
|
|
101
|
-
|
|
102
|
-
1. Open your iOS project and increase the min SDK target to iOS 13.0+
|
|
103
|
-
2. Open your `Podfile` and increase the platform:
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
..
|
|
107
|
-
platform :ios, '13'
|
|
108
|
-
..
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
3. From your React Native project's root directory, run: `cd ios && pod update`
|
|
112
|
-
4. In Xcode, change your `AppDelegate.h` to use the snippet below:
|
|
113
|
-
- This automatically syncs APNS tokens to Courier token management
|
|
114
|
-
- Allows the React Native SDK to handle when push notifications are delivered and clicked
|
|
115
|
-
|
|
116
|
-
```objective-c
|
|
117
|
-
#import <courier-react-native/CourierReactNativeDelegate.h>
|
|
118
|
-
|
|
119
|
-
@interface AppDelegate : CourierReactNativeDelegate
|
|
120
|
-
@end
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
4. Enable the "Push Notifications" capability
|
|
124
|
-
|
|
125
|
-
### **Add the Notification Service Extension (Recommended)**
|
|
126
|
-
|
|
127
|
-
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.
|
|
128
|
-
|
|
129
|
-
https://user-images.githubusercontent.com/6370613/199331562-5d16e02f-2878-4f60-bbe2-075ae119c6bc.mov
|
|
130
|
-
|
|
131
|
-
### Written Tutorial 👇
|
|
132
|
-
|
|
133
|
-
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)
|
|
134
|
-
2. Open the folder in terminal and run `sh make_template.sh`
|
|
135
|
-
- This will create the Notification Service Extension on your mac to save you time
|
|
136
|
-
3. Open your iOS app in Xcode and go to File > New > Target
|
|
137
|
-
4. Select "Courier Service" and click "Next"
|
|
138
|
-
5. Give the Notification Service Extension a name (i.e. "CourierService"), select `Courier_iOS` as the Package, and click "Finish"
|
|
139
|
-
6. Click "Cancel" on the next popup
|
|
140
|
-
- You do NOT need to click "Activate" here. Your Notification Service Extension will still work just fine.
|
|
141
|
-
7. Open your `Podfile` and add the following snippet to the end of your Podfile
|
|
142
|
-
- This will link the `Courier-iOS` pod to your Notification Service Extension
|
|
143
|
-
|
|
144
|
-
```
|
|
145
|
-
target 'CourierService' do
|
|
146
|
-
pod 'Courier-iOS'
|
|
147
|
-
end
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
8. From the root of your React Native app, run: `cd ios && pod install`
|
|
151
|
-
|
|
152
|
-
 
|
|
153
|
-
|
|
154
|
-
## **3. Android Setup**
|
|
155
|
-
|
|
156
|
-
> If you don't need push notification support on Android, you can skip this step.
|
|
157
|
-
|
|
158
|
-
https://user-images.githubusercontent.com/6370613/199335432-aa52028a-f7ae-48bb-abec-427795baa6f4.mov
|
|
159
|
-
|
|
160
|
-
### Written Tutorial 👇
|
|
161
|
-
|
|
162
|
-
1. Open Android project
|
|
163
|
-
2. Register your app in Firebase and download your `google-services.json` file
|
|
164
|
-
3. Add the `google-services.json` file to your `yourApp/app/src` directory
|
|
165
|
-
4. Make sure your `yourApp/android/build.gradle` file supports Jitpack:
|
|
166
|
-
|
|
167
|
-
```groovy
|
|
168
|
-
allprojects {
|
|
169
|
-
repositories {
|
|
170
|
-
..
|
|
171
|
-
maven { url 'https://www.jitpack.io' } // This line is needed
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
3. Update your `yourApp/android/build.gradle` to support the following SDK versions
|
|
177
|
-
- This is needed to support newer Android Notification APIs
|
|
178
|
-
|
|
179
|
-
```groovy
|
|
180
|
-
buildscript {
|
|
181
|
-
ext {
|
|
182
|
-
buildToolsVersion = "32.0.0"
|
|
183
|
-
minSdkVersion = 21
|
|
184
|
-
compileSdkVersion = 32
|
|
185
|
-
targetSdkVersion = 32
|
|
186
|
-
..
|
|
187
|
-
}
|
|
188
|
-
..
|
|
189
|
-
}
|
|
7
|
+
```sh
|
|
8
|
+
npm install courier-react-native
|
|
190
9
|
```
|
|
191
10
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
```groovy
|
|
195
|
-
buildscript {
|
|
196
|
-
dependencies {
|
|
197
|
-
..
|
|
198
|
-
classpath("com.google.gms:google-services:4.3.14") // Add this line
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
5. Add this following line to the top of your `/android/app/build.gradle` file:
|
|
204
|
-
|
|
205
|
-
```groovy
|
|
206
|
-
apply plugin: "com.android.application"
|
|
207
|
-
apply plugin: "com.google.gms.google-services" // Add this line
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
6. Run Gradle Sync
|
|
211
|
-
|
|
212
|
-
### **Update Activity and Register Service**
|
|
213
|
-
|
|
214
|
-
https://user-images.githubusercontent.com/6370613/199335233-0880209b-5aec-4584-9726-eaa1077bf80d.mov
|
|
215
|
-
|
|
216
|
-
### Written Tutorial 👇
|
|
217
|
-
|
|
218
|
-
1. Change your `MainActivity` to extend the `CourierReactNativeActivity`
|
|
219
|
-
- This allows Courier to handle when push notifications are delivered and clicked
|
|
220
|
-
2. Setup a new Notification Service by creating a new java file and paste the code below in it
|
|
221
|
-
- 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
|
|
222
|
-
|
|
223
|
-
```java
|
|
224
|
-
// Your project import
|
|
225
|
-
|
|
226
|
-
import android.annotation.SuppressLint;
|
|
227
|
-
import androidx.annotation.NonNull;
|
|
228
|
-
import com.courier.android.notifications.RemoteMessageExtensionsKt;
|
|
229
|
-
import com.courier.android.service.CourierService;
|
|
230
|
-
import com.google.firebase.messaging.RemoteMessage;
|
|
231
|
-
|
|
232
|
-
// This is safe. `CourierService` will automatically handle token refreshes.
|
|
233
|
-
@SuppressLint("MissingFirebaseInstanceTokenRefresh")
|
|
234
|
-
public class YourExampleService extends CourierService {
|
|
235
|
-
|
|
236
|
-
@Override
|
|
237
|
-
public void showNotification(@NonNull RemoteMessage message) {
|
|
238
|
-
super.showNotification(message);
|
|
239
|
-
|
|
240
|
-
// TODO: This is where you will customize the notification that is shown to your users
|
|
241
|
-
// The function below is used to get started quickly.
|
|
242
|
-
// You likely do not want to use `message.presentNotification(...)`
|
|
243
|
-
// For React Native, you likely do not want to change RemoteMessageExtensionsKt.presentNotification.handlingClass
|
|
244
|
-
// More information on how to customize an Android notification here:
|
|
245
|
-
// https://developer.android.com/develop/ui/views/notifications/build-notification
|
|
246
|
-
|
|
247
|
-
RemoteMessageExtensionsKt.presentNotification(
|
|
248
|
-
message,
|
|
249
|
-
this,
|
|
250
|
-
MainActivity.class,
|
|
251
|
-
android.R.drawable.ic_dialog_info,
|
|
252
|
-
"Notification Service"
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
3. Add the Notification Service entry in your `AndroidManifest.xml` file
|
|
261
|
-
|
|
262
|
-
```xml
|
|
263
|
-
<manifest>
|
|
264
|
-
<application>
|
|
265
|
-
|
|
266
|
-
<activity>
|
|
267
|
-
..
|
|
268
|
-
</activity>
|
|
269
|
-
|
|
270
|
-
// Add this 👇
|
|
271
|
-
<service
|
|
272
|
-
android:name=".YourExampleService"
|
|
273
|
-
android:exported="false">
|
|
274
|
-
<intent-filter>
|
|
275
|
-
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
|
276
|
-
</intent-filter>
|
|
277
|
-
</service>
|
|
278
|
-
// Add this 👆
|
|
279
|
-
|
|
280
|
-
..
|
|
281
|
-
|
|
282
|
-
</application>
|
|
283
|
-
</manifest>
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
 
|
|
287
|
-
|
|
288
|
-
## **4. Configure Push Provider**
|
|
289
|
-
|
|
290
|
-
> If you don't need push notification support, you can skip this step.
|
|
291
|
-
|
|
292
|
-
To get push notification to appear in your app, add support for the provider you would like to use:
|
|
293
|
-
|
|
294
|
-
- [`APNS (Apple Push Notification Service)`](https://app.courier.com/channels/apn)
|
|
295
|
-
- [`FCM (Firebase Cloud Messaging)`](https://app.courier.com/channels/firebase-fcm)
|
|
296
|
-
|
|
297
|
-
 
|
|
298
|
-
|
|
299
|
-
## **5. Managing User State**
|
|
300
|
-
|
|
301
|
-
Best user experience practice is to synchronize the current user's push notification tokens and the user's state. Courier does most of this for you automatically!
|
|
302
|
-
|
|
303
|
-
> You can use a Courier Auth Key [`found here`](https://app.courier.com/settings/api-keys) when developing.
|
|
304
|
-
|
|
305
|
-
> When you are ready for production release, you should be using a JWT as the `accessToken`.
|
|
306
|
-
> Here is more info about [`Going to Production`](#going-to-production)
|
|
307
|
-
|
|
308
|
-
Place these functions where you normally manage your user's state:
|
|
309
|
-
|
|
310
|
-
```dart
|
|
311
|
-
// Saves accessToken and userId to native level local storage
|
|
312
|
-
// This will persist between app sessions
|
|
313
|
-
await Courier.signIn({
|
|
314
|
-
accessToken: accessToken,
|
|
315
|
-
userId: userId,
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
await Courier.signOut();
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
If you followed the steps above:
|
|
322
|
-
|
|
323
|
-
- APNS tokens on iOS will automatically be synced to Courier
|
|
324
|
-
- FCM tokens on Android will automatically be synced to Courier
|
|
325
|
-
|
|
326
|
-
<!-- If you want FCM tokens to sync to Courier on iOS:
|
|
327
|
-
|
|
328
|
-
1. Add the following react native packages to your project
|
|
329
|
-
- [`React Native Firebase`](https://rnfirebase.io/)
|
|
330
|
-
|
|
331
|
-
2. Add code to manually sync FCM tokens
|
|
332
|
-
|
|
333
|
-
```typescript
|
|
334
|
-
const fcmToken = await FirebaseMessaging.instance.getToken();
|
|
335
|
-
if (fcmToken != null) {
|
|
336
|
-
await Courier.shared.setFcmToken(token: fcmToken);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// Handle FCM token refreshes
|
|
340
|
-
FirebaseMessaging.instance.onTokenRefresh.listen((fcmToken) {
|
|
341
|
-
Courier.shared.setFcmToken(token: fcmToken);
|
|
342
|
-
});
|
|
343
|
-
``` -->
|
|
344
|
-
|
|
345
|
-
 
|
|
346
|
-
|
|
347
|
-
## **6. Testing Push Notifications**
|
|
348
|
-
|
|
349
|
-
> If you don't need push notification support, you can skip this step.
|
|
350
|
-
|
|
351
|
-
Courier allows you to send a push notification directly from the SDK to a user id. No tokens juggling or backend needed!
|
|
352
|
-
|
|
353
|
-
```typescript
|
|
354
|
-
const notificationPermission = await Courier.notificationPermissionStatus;
|
|
355
|
-
console.log(notificationPermission);
|
|
356
|
-
|
|
357
|
-
// Notification permissions must be `authorized` on iOS to receive pushes
|
|
358
|
-
|
|
359
|
-
const requestedNotificationPermission =
|
|
360
|
-
await Courier.requestNotificationPermission();
|
|
361
|
-
console.log(requestedNotificationPermission);
|
|
362
|
-
|
|
363
|
-
// This is how iOS will show the notification when the app is in the foreground
|
|
364
|
-
// Passing [] will not present anything
|
|
365
|
-
// `onPushNotificationDelivered` will still get called
|
|
366
|
-
await Courier.iOSForegroundPresentationOptions({
|
|
367
|
-
options: ['badge', 'banner', 'list', 'sound'],
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
// This function returns an unsubscribe function
|
|
371
|
-
// Call `unsibscribe();` to stop listening to notifications
|
|
372
|
-
// Recommended to call the function while component mounts and unsubscribe when the component unmounts
|
|
373
|
-
const unsubscribe = Courier.registerPushNotificationListeners({
|
|
374
|
-
// Will be called if the app is in the foreground and a push notification arrives
|
|
375
|
-
onPushNotificationClicked(push) {
|
|
376
|
-
console.log(push.title);
|
|
377
|
-
},
|
|
378
|
-
|
|
379
|
-
// Will be called when a user clicks a push notification
|
|
380
|
-
onPushNotificationDelivered(push) {
|
|
381
|
-
console.log(push.title);
|
|
382
|
-
},
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
// Sends a test push
|
|
386
|
-
const messageId = await Courier.sendPush({
|
|
387
|
-
authKey: 'your_courier_auth_key_that_should_only_be_used_for_testing',
|
|
388
|
-
userId: 'example_user',
|
|
389
|
-
title: 'Chirp Chrip!',
|
|
390
|
-
body: 'Hello from Courier 🐣',
|
|
391
|
-
providers: [CourierProvider.APNS, CourierProvider.FCM],
|
|
392
|
-
});
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
 
|
|
396
|
-
|
|
397
|
-
## **Going to Production**
|
|
11
|
+
## Usage
|
|
398
12
|
|
|
399
|
-
|
|
13
|
+
```js
|
|
14
|
+
import { CourierReactNativeView } from "courier-react-native";
|
|
400
15
|
|
|
401
|
-
|
|
16
|
+
// ...
|
|
402
17
|
|
|
403
|
-
|
|
404
|
-
curl --request POST \
|
|
405
|
-
--url https://api.courier.com/auth/issue-token \
|
|
406
|
-
--header 'Accept: application/json' \
|
|
407
|
-
--header 'Authorization: Bearer $YOUR_AUTH_KEY' \
|
|
408
|
-
--header 'Content-Type: application/json' \
|
|
409
|
-
--data
|
|
410
|
-
'{
|
|
411
|
-
"scope": "user_id:$YOUR_USER_ID write:user-tokens",
|
|
412
|
-
"expires_in": "$YOUR_NUMBER days"
|
|
413
|
-
}'
|
|
18
|
+
<CourierReactNativeView color="tomato" />
|
|
414
19
|
```
|
|
415
20
|
|
|
416
|
-
|
|
21
|
+
## Contributing
|
|
417
22
|
|
|
418
|
-
|
|
23
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
419
24
|
|
|
420
|
-
|
|
25
|
+
## License
|
|
421
26
|
|
|
422
|
-
|
|
27
|
+
MIT
|
|
423
28
|
|
|
424
|
-
|
|
29
|
+
---
|
|
425
30
|
|
|
426
|
-
|
|
427
|
-
- [Courier React Native Issues](https://github.com/trycourier/courier-react-native/issues)
|
|
31
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
package/android/build.gradle
CHANGED
|
@@ -1,44 +1,70 @@
|
|
|
1
1
|
buildscript {
|
|
2
2
|
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
3
|
-
def kotlin_version = rootProject.ext.has(
|
|
3
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["CourierReactNative_kotlinVersion"]
|
|
4
4
|
|
|
5
5
|
repositories {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
google()
|
|
7
|
+
mavenCentral()
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
dependencies {
|
|
11
|
-
classpath
|
|
11
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
12
12
|
// noinspection DifferentKotlinGradleVersion
|
|
13
13
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
def isNewArchitectureEnabled() {
|
|
18
|
-
return rootProject.hasProperty("newArchEnabled") &&
|
|
18
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
apply plugin:
|
|
22
|
-
apply plugin:
|
|
21
|
+
apply plugin: "com.android.library"
|
|
22
|
+
apply plugin: "kotlin-android"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
|
|
23
26
|
|
|
24
27
|
if (isNewArchitectureEnabled()) {
|
|
25
|
-
apply plugin:
|
|
28
|
+
apply plugin: "com.facebook.react"
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
def getExtOrDefault(name) {
|
|
29
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties[
|
|
32
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["CourierReactNative_" + name]
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
def getExtOrIntegerDefault(name) {
|
|
33
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties[
|
|
36
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["CourierReactNative_" + name]).toInteger()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
def supportsNamespace() {
|
|
40
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
41
|
+
def major = parsed[0].toInteger()
|
|
42
|
+
def minor = parsed[1].toInteger()
|
|
43
|
+
|
|
44
|
+
// Namespace support was added in 7.3.0
|
|
45
|
+
if (major == 7 && minor >= 3) {
|
|
46
|
+
return true
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return major >= 8
|
|
34
50
|
}
|
|
35
51
|
|
|
36
52
|
android {
|
|
37
|
-
|
|
53
|
+
if (supportsNamespace()) {
|
|
54
|
+
namespace "com.courierreactnative"
|
|
55
|
+
|
|
56
|
+
sourceSets {
|
|
57
|
+
main {
|
|
58
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
38
64
|
|
|
39
65
|
defaultConfig {
|
|
40
|
-
minSdkVersion getExtOrIntegerDefault(
|
|
41
|
-
targetSdkVersion getExtOrIntegerDefault(
|
|
66
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
67
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
42
68
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
43
69
|
}
|
|
44
70
|
buildTypes {
|
|
@@ -48,102 +74,41 @@ android {
|
|
|
48
74
|
}
|
|
49
75
|
|
|
50
76
|
lintOptions {
|
|
51
|
-
disable
|
|
77
|
+
disable "GradleCompatible"
|
|
52
78
|
}
|
|
53
79
|
|
|
54
80
|
compileOptions {
|
|
55
81
|
sourceCompatibility JavaVersion.VERSION_1_8
|
|
56
82
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
57
83
|
}
|
|
84
|
+
|
|
58
85
|
}
|
|
59
86
|
|
|
60
87
|
repositories {
|
|
61
88
|
mavenCentral()
|
|
62
89
|
google()
|
|
63
90
|
maven { url 'https://jitpack.io' }
|
|
64
|
-
|
|
65
|
-
def found = false
|
|
66
|
-
def defaultDir = null
|
|
67
|
-
def androidSourcesName = 'React Native sources'
|
|
68
|
-
|
|
69
|
-
if (rootProject.ext.has('reactNativeAndroidRoot')) {
|
|
70
|
-
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
|
|
71
|
-
} else {
|
|
72
|
-
defaultDir = new File(
|
|
73
|
-
projectDir,
|
|
74
|
-
'/../../../node_modules/react-native/android'
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (defaultDir.exists()) {
|
|
79
|
-
maven {
|
|
80
|
-
url defaultDir.toString()
|
|
81
|
-
name androidSourcesName
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
|
|
85
|
-
found = true
|
|
86
|
-
} else {
|
|
87
|
-
def parentDir = rootProject.projectDir
|
|
88
|
-
|
|
89
|
-
1.upto(5, {
|
|
90
|
-
if (found) return true
|
|
91
|
-
parentDir = parentDir.parentFile
|
|
92
|
-
|
|
93
|
-
def androidSourcesDir = new File(
|
|
94
|
-
parentDir,
|
|
95
|
-
'node_modules/react-native'
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
def androidPrebuiltBinaryDir = new File(
|
|
99
|
-
parentDir,
|
|
100
|
-
'node_modules/react-native/android'
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
if (androidPrebuiltBinaryDir.exists()) {
|
|
104
|
-
maven {
|
|
105
|
-
url androidPrebuiltBinaryDir.toString()
|
|
106
|
-
name androidSourcesName
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
|
|
110
|
-
found = true
|
|
111
|
-
} else if (androidSourcesDir.exists()) {
|
|
112
|
-
maven {
|
|
113
|
-
url androidSourcesDir.toString()
|
|
114
|
-
name androidSourcesName
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
|
|
118
|
-
found = true
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (!found) {
|
|
124
|
-
throw new GradleException(
|
|
125
|
-
"${project.name}: unable to locate React Native android sources. " +
|
|
126
|
-
"Ensure you have you installed React Native as a dependency in your project and try again."
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
91
|
}
|
|
130
92
|
|
|
131
|
-
def kotlin_version = getExtOrDefault(
|
|
93
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
132
94
|
|
|
133
95
|
dependencies {
|
|
134
|
-
|
|
96
|
+
|
|
97
|
+
// For < 0.71, this will be from the local maven repo
|
|
98
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
99
|
+
//noinspection GradleDynamicVersion
|
|
135
100
|
implementation "com.facebook.react:react-native:+"
|
|
136
101
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
137
102
|
|
|
138
103
|
// Courier Core SDK
|
|
139
|
-
api 'com.github.trycourier:courier-android:
|
|
104
|
+
api 'com.github.trycourier:courier-android:2.0.2'
|
|
140
105
|
|
|
141
106
|
}
|
|
142
107
|
|
|
143
108
|
if (isNewArchitectureEnabled()) {
|
|
144
109
|
react {
|
|
145
110
|
jsRootDir = file("../src/")
|
|
146
|
-
libraryName = "
|
|
111
|
+
libraryName = "CourierReactNativeView"
|
|
147
112
|
codegenJavaPackageName = "com.courierreactnative"
|
|
148
113
|
}
|
|
149
114
|
}
|