rn-firebase-notifications-kit 0.0.0-stage โ 0.2.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/LICENSE +21 -0
- package/README.md +314 -2
- package/bin/rn-firebase-notifications-kit.js +40 -0
- package/package.json +27 -4
- package/src/core.js +356 -0
- package/src/doctor.js +173 -0
- package/src/index.d.ts +129 -0
- package/src/index.js +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hanif Mohammad
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,315 @@
|
|
|
1
|
-
#
|
|
1
|
+
# rn-firebase-notifications-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
> ### ๐ผ Built by Hanif Mohammad โ React Native & full-stack developer
|
|
6
|
+
> **Top Rated Plus on Upwork ยท 100% Job Success.** Need a React Native / Expo app built, fixed, or shipped reliably?
|
|
7
|
+
>
|
|
8
|
+
> **[โ Hire me on Upwork](https://www.upwork.com/freelancers/~01b46f78c173c3ba9b)** ยท **[โ Portfolio](https://hanif-2000.github.io)**
|
|
9
|
+
>
|
|
10
|
+
> **๐ Set it up for me:** push notifications not arriving, or not opening the right screen? I'll set up or fix push in your app at a fixed price (from $99), usually within 48 hours. **[Message me on Upwork](https://www.upwork.com/freelancers/~01b46f78c173c3ba9b)**.
|
|
11
|
+
>
|
|
12
|
+
> Found this tool useful? Please **โญ the repo** or **[sponsor on GitHub โค](https://github.com/sponsors/hanif-2000)** โ it keeps these tools maintained.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
Firebase push notifications for React Native in **two calls**: foreground, background and killed state, Android channels, permissions on both platforms, and **tap-to-navigate** โ plus a `doctor` command that checks your native setup.
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
// index.js โ above AppRegistry.registerComponent
|
|
20
|
+
import { registerBackgroundHandler } from 'rn-firebase-notifications-kit';
|
|
21
|
+
|
|
22
|
+
registerBackgroundHandler({
|
|
23
|
+
channels: [
|
|
24
|
+
{ id: 'orders', name: 'Orders' },
|
|
25
|
+
{ id: 'chat', name: 'Chat', sound: 'chat', vibration: true },
|
|
26
|
+
{ id: 'offers', name: 'Offers', importance: 'low' },
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
// App.js
|
|
33
|
+
import { useEffect } from 'react';
|
|
34
|
+
import { NavigationContainer, createNavigationContainerRef } from '@react-navigation/native';
|
|
35
|
+
import { setupPush } from 'rn-firebase-notifications-kit';
|
|
36
|
+
|
|
37
|
+
const navigationRef = createNavigationContainerRef();
|
|
38
|
+
|
|
39
|
+
export default function App() {
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
let stop;
|
|
42
|
+
setupPush({
|
|
43
|
+
navigationRef, // tap โ opens data.screen
|
|
44
|
+
onToken: (token) => api.saveDeviceToken(token), // now, and on every refresh
|
|
45
|
+
onNotification: (n) => console.log('arrived', n.title), // app is open
|
|
46
|
+
}).then((push) => { stop = push.unsubscribe; });
|
|
47
|
+
return () => stop?.();
|
|
48
|
+
}, []);
|
|
49
|
+
|
|
50
|
+
return <NavigationContainer ref={navigationRef}>{/* screens */}</NavigationContainer>;
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
It is a thin layer over [React Native Firebase Messaging](https://rnfirebase.io/messaging/usage) and [Notifee](https://notifee.app). You still install and configure those; this package wires them together correctly.
|
|
55
|
+
|
|
56
|
+
## Why
|
|
57
|
+
|
|
58
|
+
Getting a push notification to work in every app state usually means learning these one bug at a time:
|
|
59
|
+
|
|
60
|
+
- FCM **does not show anything** while the app is in the foreground. You have to display it yourself.
|
|
61
|
+
- The background handler must be registered **at the top of `index.js`**. Inside a component it never runs when the app is killed.
|
|
62
|
+
- A tap is reported by **four different APIs** depending on who displayed the notification and what state the app was in โ and sometimes by two of them at once.
|
|
63
|
+
- Android 13+ needs a runtime permission, Android 8+ needs a channel, and the FCM token changes over time.
|
|
64
|
+
|
|
65
|
+
- After a cold start the tap arrives **before your navigator exists**, so navigating straight away does nothing.
|
|
66
|
+
|
|
67
|
+
This package handles all of that.
|
|
68
|
+
|
|
69
|
+
## What it does in each state
|
|
70
|
+
|
|
71
|
+
| App state | Message arrives | User taps it |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| **Foreground** | `onNotification` runs, and a notification is shown (FCM shows none itself) | `onOpen(n, { state: 'foreground' })` |
|
|
74
|
+
| **Background** | Shown by the OS, or by this kit for data-only messages | `onOpen(n, { state: 'background' })` |
|
|
75
|
+
| **Killed** | Shown by the OS, or by this kit for data-only messages | App starts, then `onOpen(n, { state: 'quit' })` |
|
|
76
|
+
|
|
77
|
+
Each tap is delivered **once**, even when two native APIs report it. Taps that happen before your UI has mounted are queued and delivered when `setupPush` attaches.
|
|
78
|
+
|
|
79
|
+
Every callback receives the same shape:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
{ id, title, body, data, channelId, hasNotificationPayload }
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Navigation on tap
|
|
86
|
+
|
|
87
|
+
Pass your React Navigation ref and send the destination in the message data:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
"data": { "screen": "Order", "params": "{\"orderId\":42}" }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
A tap then calls `navigationRef.navigate('Order', { orderId: 42 })` โ in every app state. FCM data values are always strings, so `params` is a JSON string. After a cold start the kit waits (up to 10 seconds) for the navigator to be ready before navigating.
|
|
94
|
+
|
|
95
|
+
To decide the route yourself, or to stop navigation for a particular tap:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
setupPush({
|
|
99
|
+
navigationRef,
|
|
100
|
+
resolveRoute: (n) => (n.data.orderId ? { name: 'Order', params: { id: n.data.orderId } } : null),
|
|
101
|
+
onOpen: (n, { state }) => {
|
|
102
|
+
analytics.track('push_open', { id: n.id, state });
|
|
103
|
+
if (!isLoggedIn()) return false; // skip automatic navigation for this tap
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Not using React Navigation? Leave `navigationRef` out and handle the tap in `onOpen`.
|
|
109
|
+
|
|
110
|
+
## Channels (Android)
|
|
111
|
+
|
|
112
|
+
Define your channels once, in `registerBackgroundHandler`. They are all created on first launch, so users see them in system settings straight away, and `setupPush` reuses them.
|
|
113
|
+
|
|
114
|
+
| Field | Description |
|
|
115
|
+
|---|---|
|
|
116
|
+
| `id`, `name` | Required. `name` is what the user sees in settings. |
|
|
117
|
+
| `importance` | `'min'`, `'low'`, `'default'` or `'high'` (default `'high'`: makes a sound and shows a heads-up). |
|
|
118
|
+
| `sound` | File name in `android/app/src/main/res/raw`, without the extension. |
|
|
119
|
+
| `vibration` | `true` / `false`. |
|
|
120
|
+
| `description`, `smallIcon` | Shown in settings / used for notifications on this channel. |
|
|
121
|
+
|
|
122
|
+
A message picks its channel with `data.channelId`. With no `channelId`, or an unknown one, it goes to the default channel โ the first in the list, or `defaultChannel`. `smallIcon` and `color` next to `channels` apply to every channel.
|
|
123
|
+
|
|
124
|
+
Android does not let an app change a channel's importance or sound after it is created; that is an OS rule. To change them, use a new channel id. iOS has no channels, so this section does not apply there.
|
|
125
|
+
|
|
126
|
+
## Permissions
|
|
127
|
+
|
|
128
|
+
`setupPush` asks for permission by default and tells you where things stand:
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
const { permission } = await setupPush({ /* ... */ });
|
|
132
|
+
// { status: 'granted' | 'provisional' | 'denied' | 'blocked' | 'undetermined', granted, canAsk }
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
| Status | Meaning | What to do |
|
|
136
|
+
|---|---|---|
|
|
137
|
+
| `granted` | Notifications are allowed. | โ |
|
|
138
|
+
| `provisional` | iOS quiet delivery: goes to Notification Center, no banner or sound. | Call `requestPermission()` later to ask for full access. |
|
|
139
|
+
| `undetermined` | iOS has not asked yet. | Call `requestPermission()`. |
|
|
140
|
+
| `denied` | Android 13+: not allowed yet, the prompt can still be shown. | Call `requestPermission()`. |
|
|
141
|
+
| `blocked` | The OS will not show the prompt again. | Explain why, then `openSettings()`. |
|
|
142
|
+
|
|
143
|
+
Ask at a better moment than app start:
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
import { getPermission, requestPermission, openSettings } from 'rn-firebase-notifications-kit';
|
|
147
|
+
|
|
148
|
+
await setupPush({ requestPermission: false /* ... */ }); // attach everything, do not prompt yet
|
|
149
|
+
|
|
150
|
+
// later, e.g. after the user places their first order
|
|
151
|
+
let permission = await getPermission();
|
|
152
|
+
if (permission.canAsk) permission = await requestPermission();
|
|
153
|
+
if (permission.status === 'blocked') showBanner({ onPress: () => openSettings() });
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
What happens on each platform:
|
|
157
|
+
|
|
158
|
+
- **iOS** โ one system prompt, ever. `requestPermission({ provisional: true })` (or `setupPush({ requestPermission: { provisional: true } })`) skips the prompt and delivers quietly. Other flags: `alert`, `badge`, `sound`, `criticalAlert`, `carPlay`, `announcement`.
|
|
159
|
+
- **Android 13+** โ the runtime `POST_NOTIFICATIONS` prompt. After the user declines twice Android stops showing it and the status becomes `blocked`.
|
|
160
|
+
- **Android 12 and older** โ there is no prompt; notifications are on unless the user turned them off in settings (`blocked`).
|
|
161
|
+
|
|
162
|
+
### When permission is granted but nothing arrives (Android)
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
import { getRestrictions, openBatterySettings, openPowerManagerSettings, openSettings } from 'rn-firebase-notifications-kit';
|
|
166
|
+
|
|
167
|
+
const r = await getRestrictions();
|
|
168
|
+
// { batteryOptimized: true, powerManager: { manufacturer: 'xiaomi', model: '...' }, blockedChannels: ['offers'] }
|
|
169
|
+
|
|
170
|
+
if (r.powerManager) openPowerManagerSettings(); // Xiaomi, Oppo, Vivo, Huawei: allow the app to run in the background
|
|
171
|
+
else if (r.batteryOptimized) openBatterySettings();
|
|
172
|
+
if (r.blockedChannels.length) openSettings(r.blockedChannels[0]); // the user switched this channel off
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Install
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
npm install rn-firebase-notifications-kit @react-native-firebase/app @react-native-firebase/messaging @notifee/react-native
|
|
179
|
+
cd ios && pod install
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Then follow the native setup for [React Native Firebase](https://rnfirebase.io/#installation) (add `google-services.json` / `GoogleService-Info.plist`, enable the Push Notifications capability and upload an APNs key in the Firebase console), and check it:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
npx rn-firebase-notifications-kit doctor
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## doctor
|
|
189
|
+
|
|
190
|
+
Reads your project files and reports what is missing. It does not build anything or need Xcode or the Android SDK.
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
rn-firebase-notifications-kit doctor ยท /work/my-app
|
|
194
|
+
|
|
195
|
+
โ Firebase Messaging and Notifee are installed
|
|
196
|
+
Missing: @notifee/react-native
|
|
197
|
+
fix: npm install @notifee/react-native
|
|
198
|
+
โ Background handler is registered in the entry file
|
|
199
|
+
โ android/app/google-services.json exists
|
|
200
|
+
โ google-services.json matches the app id
|
|
201
|
+
โ Google services Gradle plugin is applied
|
|
202
|
+
โ POST_NOTIFICATIONS permission is declared
|
|
203
|
+
โ GoogleService-Info.plist exists
|
|
204
|
+
โ Push Notifications capability is enabled
|
|
205
|
+
! Remote notifications background mode is on
|
|
206
|
+
Without it iOS does not wake the app for data-only (silent) messages.
|
|
207
|
+
fix: Xcode โ Signing & Capabilities โ Background Modes โ Remote notifications
|
|
208
|
+
โ Firebase is configured in AppDelegate
|
|
209
|
+
|
|
210
|
+
8 passed ยท 1 failed ยท 1 warning
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
| Option | Description |
|
|
214
|
+
|---|---|
|
|
215
|
+
| `doctor [dir]` | Project root to check (default: current directory) |
|
|
216
|
+
| `--json` | Machine-readable output |
|
|
217
|
+
| `-v`, `--version` | Print the version |
|
|
218
|
+
| `-h`, `--help` | Show help |
|
|
219
|
+
|
|
220
|
+
Exit code `0` when nothing failed, `1` when at least one check failed, `2` for a usage error โ so it can run in CI. Bare React Native and prebuilt Expo projects are checked through `android/` and `ios/`; managed Expo projects through `app.json`.
|
|
221
|
+
|
|
222
|
+
## Sending messages
|
|
223
|
+
|
|
224
|
+
What your server sends decides who displays the notification.
|
|
225
|
+
|
|
226
|
+
**Notification + data** โ the simplest and most reliable. The OS displays it in background and killed state; this kit displays it in the foreground.
|
|
227
|
+
|
|
228
|
+
```json
|
|
229
|
+
{
|
|
230
|
+
"message": {
|
|
231
|
+
"token": "<device token>",
|
|
232
|
+
"notification": { "title": "Order shipped", "body": "Arriving Friday" },
|
|
233
|
+
"data": { "screen": "Order", "params": "{\"orderId\":42}", "channelId": "orders" }
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Data-only** โ this kit displays it in every state, using `data.title` and `data.body`. Send it with high priority or Android may delay it.
|
|
239
|
+
|
|
240
|
+
```json
|
|
241
|
+
{
|
|
242
|
+
"message": {
|
|
243
|
+
"token": "<device token>",
|
|
244
|
+
"data": { "title": "Order shipped", "body": "Arriving Friday", "screen": "Order", "params": "{\"orderId\":42}", "channelId": "orders" },
|
|
245
|
+
"android": { "priority": "high" },
|
|
246
|
+
"apns": { "headers": { "apns-priority": "5" }, "payload": { "aps": { "content-available": 1 } } }
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
A data-only message with no `title` and no `body` is treated as silent: your callbacks run and nothing is shown.
|
|
252
|
+
|
|
253
|
+
## API
|
|
254
|
+
|
|
255
|
+
### `registerBackgroundHandler(options?)`
|
|
256
|
+
|
|
257
|
+
Call once in `index.js`, before `AppRegistry.registerComponent`.
|
|
258
|
+
|
|
259
|
+
| Option | Default | Description |
|
|
260
|
+
|---|---|---|
|
|
261
|
+
| `channels` | `[{ id: 'default', name: 'General' }]` | Android channels. See [Channels](#channels-android). |
|
|
262
|
+
| `defaultChannel` | first channel | Channel for messages that name none. |
|
|
263
|
+
| `smallIcon`, `color` | โ | Android small icon resource name and accent colour for every notification. |
|
|
264
|
+
| `decorate(n, payload)` | โ | Change the Notifee payload before display (image, actions, style). Return the new payload. |
|
|
265
|
+
| `onEvent(event, { state, notification })` | โ | Receives every Notifee event, e.g. action-button presses and dismissals. |
|
|
266
|
+
| `display` | `true` | Show data-only messages as notifications. |
|
|
267
|
+
| `onMessage(n, remoteMessage)` | โ | Runs for every background / killed-state message, before it is displayed. Keep it short; Android gives a headless task limited time. |
|
|
268
|
+
|
|
269
|
+
### `setupPush(options?)` โ `Promise<{ granted, permission, token, unsubscribe }>`
|
|
270
|
+
|
|
271
|
+
Call once after the app mounts.
|
|
272
|
+
|
|
273
|
+
| Option | Default | Description |
|
|
274
|
+
|---|---|---|
|
|
275
|
+
| `onNotification(n, remoteMessage)` | โ | A message arrived while the app is in the foreground. |
|
|
276
|
+
| `onOpen(n, { state })` | โ | The user tapped a notification. `state` is `'foreground'`, `'background'` or `'quit'`. Return `false` to skip automatic navigation. |
|
|
277
|
+
| `navigationRef` | โ | React Navigation container ref. A tap opens `data.screen` with `data.params`. |
|
|
278
|
+
| `resolveRoute(n, { state })` | reads `data.screen` / `data.params` | Return `{ name, params }`, or `null` to stay put. |
|
|
279
|
+
| `onToken(token)` | โ | The FCM token, now and whenever it refreshes. |
|
|
280
|
+
| `onError(error)` | โ | Errors from token retrieval or from your callbacks. |
|
|
281
|
+
| `requestPermission` | `true` | `true` asks now, `false` only reads the current state, an object passes iOS options such as `{ provisional: true }`. |
|
|
282
|
+
| `showInForeground` | `true` | Show a notification for foreground messages. |
|
|
283
|
+
|
|
284
|
+
`granted` is `false` when the user declined. Listeners are still attached, so data messages keep arriving on Android.
|
|
285
|
+
|
|
286
|
+
### Other functions
|
|
287
|
+
|
|
288
|
+
| Function | Returns |
|
|
289
|
+
|---|---|
|
|
290
|
+
| `getPermission()` | `{ status, granted, canAsk }` without prompting |
|
|
291
|
+
| `requestPermission(iosOptions?)` | `{ status, granted, canAsk }` after prompting |
|
|
292
|
+
| `openSettings(channelId?)` | Opens the app's notification settings, or one channel's |
|
|
293
|
+
| `getRestrictions()` | `{ batteryOptimized, powerManager, blockedChannels }` (Android) |
|
|
294
|
+
| `openBatterySettings()`, `openPowerManagerSettings()` | Open the matching Android settings screen |
|
|
295
|
+
|
|
296
|
+
TypeScript types are included.
|
|
297
|
+
|
|
298
|
+
## Limits
|
|
299
|
+
|
|
300
|
+
- **It cannot do the native setup for you.** You still need a Firebase project, the config files and an APNs key. `doctor` finds what is missing in your files; it cannot see your Firebase console.
|
|
301
|
+
- **Delivery is up to the OS.** iOS does not deliver data-only messages to an app the user force-quit, and throttles silent pushes. Some Android phones (Xiaomi, Oppo, Vivo and others) stop background apps unless the user exempts them. Use a notification payload for anything the user must see.
|
|
302
|
+
- **Not for Expo Go.** Firebase Messaging and Notifee contain native code; use a development build.
|
|
303
|
+
- Local/scheduled notifications, topics, badges and rich media are not wrapped. Call Notifee or Firebase Messaging directly for those; they work alongside this kit.
|
|
304
|
+
|
|
305
|
+
This is an independent open-source project. It is not affiliated with or endorsed by Google, Firebase or Notifee.
|
|
306
|
+
|
|
307
|
+
## Sponsors
|
|
308
|
+
|
|
309
|
+
This tool is free and MIT-licensed. Sponsorship pays for keeping it up to date with new store rules and new React Native / Expo versions.
|
|
310
|
+
|
|
311
|
+
**[Become the first sponsor โ](https://github.com/sponsors/hanif-2000)**
|
|
312
|
+
|
|
313
|
+
## License
|
|
314
|
+
|
|
315
|
+
MIT ยฉ [Hanif Mohammad](https://hanif-2000.github.io)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { runDoctor, formatReport } from '../src/doctor.js';
|
|
4
|
+
|
|
5
|
+
const HELP = `rn-firebase-notifications-kit โ check a React Native project's Firebase push setup
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
npx rn-firebase-notifications-kit doctor [project-dir] [--json]
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
--json Machine-readable output
|
|
12
|
+
-v, --version Print the version
|
|
13
|
+
-h, --help Show help
|
|
14
|
+
|
|
15
|
+
Exit codes: 0 no failures ยท 1 at least one check failed ยท 2 usage error`;
|
|
16
|
+
|
|
17
|
+
const args = process.argv.slice(2);
|
|
18
|
+
const flags = new Set(args.filter((a) => a.startsWith('-')));
|
|
19
|
+
const positional = args.filter((a) => !a.startsWith('-'));
|
|
20
|
+
|
|
21
|
+
if (flags.has('-h') || flags.has('--help') || args.length === 0) { console.log(HELP); process.exit(args.length === 0 ? 2 : 0); }
|
|
22
|
+
if (flags.has('-v') || flags.has('--version')) {
|
|
23
|
+
console.log(JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version);
|
|
24
|
+
process.exit(0);
|
|
25
|
+
}
|
|
26
|
+
const unknown = [...flags].filter((f) => f !== '--json');
|
|
27
|
+
if (positional[0] !== 'doctor' || unknown.length) {
|
|
28
|
+
console.error(unknown.length ? `Unknown option: ${unknown[0]}` : `Unknown command: ${positional[0]}`);
|
|
29
|
+
console.error('Run with --help to see usage.');
|
|
30
|
+
process.exit(2);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const report = runDoctor(positional[1] || process.cwd());
|
|
35
|
+
console.log(flags.has('--json') ? JSON.stringify(report, null, 2) : formatReport(report));
|
|
36
|
+
process.exit(report.summary.failed > 0 ? 1 : 0);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error(error.message);
|
|
39
|
+
process.exit(2);
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-firebase-notifications-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Firebase push notifications for React Native in two calls: foreground, background and killed state, one tap handler for all three, plus a doctor command that checks your native setup. Built on React Native Firebase Messaging and Notifee.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": { "types": "./src/index.d.ts", "default": "./src/index.js" },
|
|
10
|
+
"./core": "./src/core.js",
|
|
11
|
+
"./doctor": "./src/doctor.js"
|
|
12
|
+
},
|
|
13
|
+
"bin": { "rn-firebase-notifications-kit": "bin/rn-firebase-notifications-kit.js" },
|
|
14
|
+
"files": ["bin", "src", "README.md", "LICENSE"],
|
|
15
|
+
"scripts": { "test": "node --test" },
|
|
16
|
+
"engines": { "node": ">=18" },
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@notifee/react-native": ">=7",
|
|
19
|
+
"@react-native-firebase/app": ">=18",
|
|
20
|
+
"@react-native-firebase/messaging": ">=18",
|
|
21
|
+
"react-native": ">=0.71"
|
|
22
|
+
},
|
|
23
|
+
"keywords": ["react-native", "firebase", "fcm", "push-notifications", "notifications", "notifee", "firebase-messaging", "background", "killed-state", "expo", "android", "ios", "cli"],
|
|
24
|
+
"author": "Hanif Mohammad (https://hanif-2000.github.io)",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": { "type": "git", "url": "git+https://github.com/hanif-2000/rn-firebase-notifications-kit.git" },
|
|
27
|
+
"bugs": { "url": "https://github.com/hanif-2000/rn-firebase-notifications-kit/issues" },
|
|
28
|
+
"homepage": "https://github.com/hanif-2000/rn-firebase-notifications-kit#readme"
|
|
29
|
+
}
|
package/src/core.js
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* rn-firebase-notifications-kit core. No imports from react-native, Firebase or Notifee here:
|
|
3
|
+
* everything arrives through `deps`, so this file runs (and is tested) in plain Node.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const ID_KEY = '_rnfnkId';
|
|
7
|
+
export const DEFAULT_CHANNEL = { id: 'default', name: 'General' };
|
|
8
|
+
const NAVIGATION_RETRY_MS = 100;
|
|
9
|
+
const NAVIGATION_MAX_ATTEMPTS = 100; // 10 seconds
|
|
10
|
+
|
|
11
|
+
/** Turn an FCM RemoteMessage into the one shape every callback receives. */
|
|
12
|
+
export function normalizeRemoteMessage(remoteMessage) {
|
|
13
|
+
const payload = remoteMessage?.notification;
|
|
14
|
+
const data = { ...(remoteMessage?.data || {}) };
|
|
15
|
+
return {
|
|
16
|
+
id: remoteMessage?.messageId ?? data.id ?? null,
|
|
17
|
+
title: payload?.title ?? data.title ?? null,
|
|
18
|
+
body: payload?.body ?? data.body ?? null,
|
|
19
|
+
data,
|
|
20
|
+
channelId: data.channelId ?? payload?.android?.channelId ?? null,
|
|
21
|
+
hasNotificationPayload: Boolean(payload),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Turn a Notifee notification (one this kit displayed) back into the same shape. */
|
|
26
|
+
export function normalizeDisplayed(notification) {
|
|
27
|
+
const { [ID_KEY]: kitId, ...data } = notification?.data || {};
|
|
28
|
+
return {
|
|
29
|
+
id: kitId ?? notification?.id ?? null,
|
|
30
|
+
title: notification?.title ?? null,
|
|
31
|
+
body: notification?.body ?? null,
|
|
32
|
+
data,
|
|
33
|
+
channelId: notification?.android?.channelId ?? data.channelId ?? null,
|
|
34
|
+
hasNotificationPayload: false,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Default tap โ route mapping: `data.screen` is the route name, `data.params` a JSON object string. */
|
|
39
|
+
export function defaultResolveRoute(notification) {
|
|
40
|
+
const name = notification?.data?.screen;
|
|
41
|
+
if (!name) return null;
|
|
42
|
+
const raw = notification.data.params;
|
|
43
|
+
if (raw === undefined || raw === null || raw === '') return { name, params: undefined };
|
|
44
|
+
if (typeof raw === 'object') return { name, params: raw };
|
|
45
|
+
let params;
|
|
46
|
+
try { params = JSON.parse(raw); } catch { throw new Error(`data.params is not valid JSON: ${raw}`); }
|
|
47
|
+
return { name, params };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function createPushKit(deps) {
|
|
51
|
+
const { fm, notifee, EventType, AndroidImportance, AuthorizationStatus, platform } = deps;
|
|
52
|
+
const messaging = () => fm.getMessaging();
|
|
53
|
+
|
|
54
|
+
const schedule = deps.setTimeout ?? ((fn, ms) => setTimeout(fn, ms));
|
|
55
|
+
|
|
56
|
+
let openListener = null;
|
|
57
|
+
const pendingOpens = []; // taps that arrived before setupPush() attached a listener
|
|
58
|
+
const seenOpens = new Set(); // one tap can be reported by two APIs; deliver it once
|
|
59
|
+
const channelsReady = new Set();
|
|
60
|
+
// Shared by registerBackgroundHandler() and setupPush(): define channels once, in index.js.
|
|
61
|
+
const config = { channels: [DEFAULT_CHANNEL], defaultChannel: DEFAULT_CHANNEL.id, smallIcon: undefined, color: undefined, decorate: undefined, onEvent: undefined };
|
|
62
|
+
|
|
63
|
+
function importanceOf(value) {
|
|
64
|
+
if (typeof value === 'number') return value;
|
|
65
|
+
if (value === undefined) return AndroidImportance.HIGH;
|
|
66
|
+
const level = AndroidImportance[String(value).toUpperCase()];
|
|
67
|
+
if (level === undefined) throw new Error(`Unknown channel importance "${value}". Use 'min', 'low', 'default' or 'high'.`);
|
|
68
|
+
return level;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function applyConfig(options) {
|
|
72
|
+
if (options.channels !== undefined) {
|
|
73
|
+
if (!Array.isArray(options.channels) || options.channels.length === 0) throw new Error('channels must be a non-empty array.');
|
|
74
|
+
for (const channel of options.channels) {
|
|
75
|
+
if (!channel?.id || !channel?.name) throw new Error('Every channel needs an id and a name.');
|
|
76
|
+
}
|
|
77
|
+
config.channels = options.channels;
|
|
78
|
+
config.defaultChannel = options.channels[0].id;
|
|
79
|
+
}
|
|
80
|
+
if (options.defaultChannel !== undefined) config.defaultChannel = options.defaultChannel;
|
|
81
|
+
if (!config.channels.some((c) => c.id === config.defaultChannel)) {
|
|
82
|
+
throw new Error(`defaultChannel "${config.defaultChannel}" is not one of the configured channels.`);
|
|
83
|
+
}
|
|
84
|
+
if (options.smallIcon !== undefined) config.smallIcon = options.smallIcon;
|
|
85
|
+
if (options.color !== undefined) config.color = options.color;
|
|
86
|
+
if (options.decorate !== undefined) config.decorate = options.decorate;
|
|
87
|
+
if (options.onEvent !== undefined) config.onEvent = options.onEvent;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Create every configured channel, so they all appear in the system settings from first launch. */
|
|
91
|
+
async function ensureChannels() {
|
|
92
|
+
if (platform !== 'android') return;
|
|
93
|
+
for (const channel of config.channels) {
|
|
94
|
+
if (channelsReady.has(channel.id)) continue;
|
|
95
|
+
const spec = { id: channel.id, name: channel.name, importance: importanceOf(channel.importance) };
|
|
96
|
+
if (channel.description) spec.description = channel.description;
|
|
97
|
+
if (channel.sound) spec.sound = channel.sound;
|
|
98
|
+
if (channel.vibration !== undefined) spec.vibration = channel.vibration;
|
|
99
|
+
await notifee.createChannel(spec);
|
|
100
|
+
channelsReady.add(channel.id);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The channel a message asked for, or the default when it asked for none / an unknown one. */
|
|
105
|
+
function channelFor(notification) {
|
|
106
|
+
return config.channels.find((c) => c.id === notification.channelId)
|
|
107
|
+
?? config.channels.find((c) => c.id === config.defaultChannel);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function display(notification) {
|
|
111
|
+
await ensureChannels();
|
|
112
|
+
const channel = channelFor(notification);
|
|
113
|
+
const data = { ...notification.data };
|
|
114
|
+
if (notification.id) data[ID_KEY] = notification.id;
|
|
115
|
+
const android = { channelId: channel.id, pressAction: { id: 'default' } };
|
|
116
|
+
const smallIcon = channel.smallIcon ?? config.smallIcon;
|
|
117
|
+
if (smallIcon) android.smallIcon = smallIcon;
|
|
118
|
+
if (config.color) android.color = config.color;
|
|
119
|
+
const payload = {
|
|
120
|
+
title: notification.title ?? undefined,
|
|
121
|
+
body: notification.body ?? undefined,
|
|
122
|
+
data,
|
|
123
|
+
android,
|
|
124
|
+
};
|
|
125
|
+
// Extension point: `decorate` may return a changed payload (images, actions, styles).
|
|
126
|
+
const decorated = config.decorate ? await config.decorate(notification, payload) : payload;
|
|
127
|
+
await notifee.displayNotification(decorated ?? payload);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Extension point: every Notifee event is also passed to `onEvent`, with the notification in this kit's shape. */
|
|
131
|
+
async function forwardEvent(event, state) {
|
|
132
|
+
if (!config.onEvent) return;
|
|
133
|
+
const notification = event?.detail?.notification ? normalizeDisplayed(event.detail.notification) : null;
|
|
134
|
+
await config.onEvent(event, { state, notification });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function emitOpen(notification, state) {
|
|
138
|
+
if (notification.id) {
|
|
139
|
+
if (seenOpens.has(notification.id)) return;
|
|
140
|
+
seenOpens.add(notification.id);
|
|
141
|
+
}
|
|
142
|
+
if (openListener) openListener(notification, { state });
|
|
143
|
+
else pendingOpens.push({ notification, state });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const POST_NOTIFICATIONS = 'android.permission.POST_NOTIFICATIONS';
|
|
147
|
+
// Android 13 (API 33) is the first version with a runtime notification permission.
|
|
148
|
+
const hasRuntimePermission = platform === 'android' && Number(deps.apiLevel) >= 33 && Boolean(deps.PermissionsAndroid);
|
|
149
|
+
|
|
150
|
+
const permissionResult = (status) => ({
|
|
151
|
+
status,
|
|
152
|
+
granted: status === 'granted' || status === 'provisional',
|
|
153
|
+
// 'blocked' means the OS will not show the prompt again; only the settings screen can change it.
|
|
154
|
+
canAsk: status === 'undetermined' || status === 'denied' || status === 'provisional',
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
function statusFromSettings(settings) {
|
|
158
|
+
const value = settings?.authorizationStatus;
|
|
159
|
+
if (value === AuthorizationStatus.AUTHORIZED) return 'granted';
|
|
160
|
+
if (value === AuthorizationStatus.PROVISIONAL) return 'provisional';
|
|
161
|
+
if (value === AuthorizationStatus.NOT_DETERMINED) return 'undetermined';
|
|
162
|
+
// DENIED: iOS never prompts twice, and before Android 13 it means notifications were switched off in settings.
|
|
163
|
+
return hasRuntimePermission ? 'denied' : 'blocked';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Current permission, without showing a prompt. */
|
|
167
|
+
async function getPermission() {
|
|
168
|
+
return permissionResult(statusFromSettings(await notifee.getNotificationSettings()));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Ask for notification permission.
|
|
173
|
+
* iOS: pass `{ provisional: true }` for quiet delivery without a prompt, or any Notifee iOS permission flag.
|
|
174
|
+
* Android 13+: shows the system prompt. Older Android has no prompt.
|
|
175
|
+
*/
|
|
176
|
+
async function requestPermission(options = {}) {
|
|
177
|
+
if (hasRuntimePermission) {
|
|
178
|
+
const result = await deps.PermissionsAndroid.request(POST_NOTIFICATIONS);
|
|
179
|
+
if (result === 'granted') return permissionResult('granted');
|
|
180
|
+
return permissionResult(result === 'never_ask_again' ? 'blocked' : 'denied');
|
|
181
|
+
}
|
|
182
|
+
const settings = platform === 'ios' ? await notifee.requestPermission(options) : await notifee.requestPermission();
|
|
183
|
+
return permissionResult(statusFromSettings(settings));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Open this app's notification settings (for a channel, when a channel id is given). */
|
|
187
|
+
async function openSettings(channelId) {
|
|
188
|
+
await notifee.openNotificationSettings(channelId);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Things on the device that stop notifications even though permission is granted.
|
|
193
|
+
* Android only; on iOS every field is empty.
|
|
194
|
+
*/
|
|
195
|
+
async function getRestrictions() {
|
|
196
|
+
const none = { batteryOptimized: false, powerManager: null, blockedChannels: [] };
|
|
197
|
+
if (platform !== 'android') return none;
|
|
198
|
+
const [batteryOptimized, info] = await Promise.all([
|
|
199
|
+
notifee.isBatteryOptimizationEnabled(),
|
|
200
|
+
notifee.getPowerManagerInfo(),
|
|
201
|
+
]);
|
|
202
|
+
const blockedChannels = [];
|
|
203
|
+
for (const channel of config.channels) {
|
|
204
|
+
if (await notifee.isChannelBlocked(channel.id)) blockedChannels.push(channel.id);
|
|
205
|
+
}
|
|
206
|
+
// `activity` is set only on phones that ship their own background-app killer (Xiaomi, Oppo, Vivo, Huawei, ...).
|
|
207
|
+
const powerManager = info?.activity ? { manufacturer: info.manufacturer ?? null, model: info.model ?? null } : null;
|
|
208
|
+
return { batteryOptimized: Boolean(batteryOptimized), powerManager, blockedChannels };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const openBatterySettings = () => notifee.openBatteryOptimizationSettings();
|
|
212
|
+
const openPowerManagerSettings = () => notifee.openPowerManagerSettings();
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Call once in index.js, before AppRegistry.registerComponent.
|
|
216
|
+
* Android starts a headless JS task for background / killed-state messages and
|
|
217
|
+
* only code that runs at the top of the entry file is loaded in that task.
|
|
218
|
+
*/
|
|
219
|
+
function registerBackgroundHandler(options = {}) {
|
|
220
|
+
const { display: shouldDisplay = true, onMessage } = options;
|
|
221
|
+
applyConfig(options);
|
|
222
|
+
|
|
223
|
+
fm.setBackgroundMessageHandler(messaging(), async (remoteMessage) => {
|
|
224
|
+
const notification = normalizeRemoteMessage(remoteMessage);
|
|
225
|
+
if (onMessage) await onMessage(notification, remoteMessage);
|
|
226
|
+
// A message with a `notification` payload is already shown by the OS.
|
|
227
|
+
// Showing it again here would produce two notifications.
|
|
228
|
+
const hasText = Boolean(notification.title || notification.body);
|
|
229
|
+
if (shouldDisplay && !notification.hasNotificationPayload && hasText) {
|
|
230
|
+
await display(notification);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
notifee.onBackgroundEvent(async (event) => {
|
|
235
|
+
const { type, detail } = event;
|
|
236
|
+
if (type === EventType.PRESS && detail?.notification) {
|
|
237
|
+
emitOpen(normalizeDisplayed(detail.notification), 'background');
|
|
238
|
+
}
|
|
239
|
+
await forwardEvent(event, 'background');
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Call once after the app has mounted (e.g. in a root useEffect). */
|
|
244
|
+
async function setupPush(options = {}) {
|
|
245
|
+
const {
|
|
246
|
+
onNotification,
|
|
247
|
+
onOpen,
|
|
248
|
+
onToken,
|
|
249
|
+
onError,
|
|
250
|
+
navigationRef,
|
|
251
|
+
resolveRoute = defaultResolveRoute,
|
|
252
|
+
requestPermission: askPermission = true,
|
|
253
|
+
showInForeground = true,
|
|
254
|
+
} = options;
|
|
255
|
+
const unsubscribers = [];
|
|
256
|
+
let active = true;
|
|
257
|
+
const report = (error) => { if (onError) onError(error); };
|
|
258
|
+
|
|
259
|
+
applyConfig(options);
|
|
260
|
+
await ensureChannels();
|
|
261
|
+
|
|
262
|
+
// After a cold start the tap arrives before the navigator has mounted, so wait for it.
|
|
263
|
+
function navigateWhenReady(route, attempt = 0) {
|
|
264
|
+
if (!active) return;
|
|
265
|
+
if (navigationRef.isReady()) { navigationRef.navigate(route.name, route.params); return; }
|
|
266
|
+
if (attempt >= NAVIGATION_MAX_ATTEMPTS) {
|
|
267
|
+
report(new Error(`Navigation was not ready after ${(NAVIGATION_MAX_ATTEMPTS * NAVIGATION_RETRY_MS) / 1000}s; could not open "${route.name}". Is navigationRef passed to <NavigationContainer ref={...}>?`));
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
schedule(() => navigateWhenReady(route, attempt + 1), NAVIGATION_RETRY_MS);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function handleOpen(notification, info) {
|
|
274
|
+
try {
|
|
275
|
+
const handled = onOpen ? onOpen(notification, info) : undefined;
|
|
276
|
+
if (handled === false || !navigationRef) return; // returning false from onOpen skips automatic navigation
|
|
277
|
+
const route = resolveRoute(notification, info);
|
|
278
|
+
if (route?.name) navigateWhenReady(route);
|
|
279
|
+
} catch (error) { report(error); }
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// true โ ask with defaults; an object โ iOS options such as { provisional: true }; false โ only read the current state.
|
|
283
|
+
const permission = askPermission
|
|
284
|
+
? await requestPermission(typeof askPermission === 'object' ? askPermission : {})
|
|
285
|
+
: await getPermission();
|
|
286
|
+
const granted = permission.granted;
|
|
287
|
+
|
|
288
|
+
unsubscribers.push(fm.onMessage(messaging(), async (remoteMessage) => {
|
|
289
|
+
try {
|
|
290
|
+
const notification = normalizeRemoteMessage(remoteMessage);
|
|
291
|
+
if (onNotification) onNotification(notification, remoteMessage);
|
|
292
|
+
// FCM never shows a notification while the app is in the foreground.
|
|
293
|
+
if (showInForeground && (notification.title || notification.body)) {
|
|
294
|
+
await display(notification);
|
|
295
|
+
}
|
|
296
|
+
} catch (error) { report(error); }
|
|
297
|
+
}));
|
|
298
|
+
|
|
299
|
+
// Tap on an OS-displayed notification while the app was in the background.
|
|
300
|
+
unsubscribers.push(fm.onNotificationOpenedApp(messaging(), (remoteMessage) => {
|
|
301
|
+
emitOpen(normalizeRemoteMessage(remoteMessage), 'background');
|
|
302
|
+
}));
|
|
303
|
+
|
|
304
|
+
// Tap on a notification this kit displayed, while the app is in the foreground.
|
|
305
|
+
unsubscribers.push(notifee.onForegroundEvent((event) => {
|
|
306
|
+
const { type, detail } = event;
|
|
307
|
+
if (type === EventType.PRESS && detail?.notification) {
|
|
308
|
+
emitOpen(normalizeDisplayed(detail.notification), 'foreground');
|
|
309
|
+
}
|
|
310
|
+
forwardEvent(event, 'foreground').catch(report);
|
|
311
|
+
}));
|
|
312
|
+
|
|
313
|
+
openListener = handleOpen;
|
|
314
|
+
|
|
315
|
+
// Did a notification tap launch the app from the killed state?
|
|
316
|
+
try {
|
|
317
|
+
const fromOs = await fm.getInitialNotification(messaging());
|
|
318
|
+
if (fromOs) emitOpen(normalizeRemoteMessage(fromOs), 'quit');
|
|
319
|
+
|
|
320
|
+
const fromKit = await notifee.getInitialNotification();
|
|
321
|
+
if (fromKit?.notification) {
|
|
322
|
+
const notification = normalizeDisplayed(fromKit.notification);
|
|
323
|
+
// The same tap may already be queued by onBackgroundEvent; it launched the app, so it is a 'quit' open.
|
|
324
|
+
const queued = pendingOpens.find((p) => notification.id && p.notification.id === notification.id);
|
|
325
|
+
if (queued) queued.state = 'quit';
|
|
326
|
+
else emitOpen(notification, 'quit');
|
|
327
|
+
}
|
|
328
|
+
} catch (error) { report(error); }
|
|
329
|
+
|
|
330
|
+
for (const { notification, state } of pendingOpens.splice(0)) handleOpen(notification, { state });
|
|
331
|
+
|
|
332
|
+
let token = null;
|
|
333
|
+
try {
|
|
334
|
+
token = await fm.getToken(messaging());
|
|
335
|
+
if (token && onToken) onToken(token);
|
|
336
|
+
} catch (error) { report(error); }
|
|
337
|
+
unsubscribers.push(fm.onTokenRefresh(messaging(), (next) => { if (onToken) onToken(next); }));
|
|
338
|
+
|
|
339
|
+
return {
|
|
340
|
+
granted,
|
|
341
|
+
permission,
|
|
342
|
+
token,
|
|
343
|
+
unsubscribe() {
|
|
344
|
+
active = false;
|
|
345
|
+
for (const off of unsubscribers.splice(0)) if (typeof off === 'function') off();
|
|
346
|
+
openListener = null;
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return {
|
|
352
|
+
registerBackgroundHandler, setupPush,
|
|
353
|
+
getPermission, requestPermission, openSettings,
|
|
354
|
+
getRestrictions, openBatterySettings, openPowerManagerSettings,
|
|
355
|
+
};
|
|
356
|
+
}
|
package/src/doctor.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const read = (file) => { try { return fs.readFileSync(file, 'utf8'); } catch { return null; } };
|
|
5
|
+
const exists = (file) => fs.existsSync(file);
|
|
6
|
+
const SKIP_DIRS = new Set(['node_modules', 'Pods', 'build', 'DerivedData', '.git', '.gradle']);
|
|
7
|
+
|
|
8
|
+
/** Files under `dir` (bounded depth) whose name passes `test`. */
|
|
9
|
+
function findFiles(dir, test, depth = 4) {
|
|
10
|
+
const found = [];
|
|
11
|
+
let entries = [];
|
|
12
|
+
try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return found; }
|
|
13
|
+
for (const entry of entries) {
|
|
14
|
+
const full = path.join(dir, entry.name);
|
|
15
|
+
if (entry.isDirectory()) {
|
|
16
|
+
if (depth > 0 && !SKIP_DIRS.has(entry.name)) found.push(...findFiles(full, test, depth - 1));
|
|
17
|
+
} else if (test(entry.name)) found.push(full);
|
|
18
|
+
}
|
|
19
|
+
return found;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DEPS = ['@react-native-firebase/app', '@react-native-firebase/messaging', '@notifee/react-native'];
|
|
23
|
+
|
|
24
|
+
function checkJs(root, pkg, add) {
|
|
25
|
+
const deps = { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) };
|
|
26
|
+
const missing = DEPS.filter((name) => !deps[name]);
|
|
27
|
+
add('deps', missing.length ? 'fail' : 'pass', 'Firebase Messaging and Notifee are installed',
|
|
28
|
+
missing.length ? `Missing: ${missing.join(', ')}` : null,
|
|
29
|
+
missing.length ? `npm install ${missing.join(' ')}` : null);
|
|
30
|
+
|
|
31
|
+
const candidates = [pkg.main, 'index.js', 'index.ts', 'index.tsx'].filter(Boolean).map((f) => path.join(root, f));
|
|
32
|
+
const entry = candidates.find((f) => exists(f) && fs.statSync(f).isFile());
|
|
33
|
+
if (!entry) {
|
|
34
|
+
add('entry', 'warn', 'Background handler is registered in the entry file',
|
|
35
|
+
'Could not find the entry file (index.js) to check.', null);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const source = read(entry) || '';
|
|
39
|
+
const ok = /registerBackgroundHandler\s*\(|setBackgroundMessageHandler\s*\(/.test(source);
|
|
40
|
+
add('entry', ok ? 'pass' : 'fail', 'Background handler is registered in the entry file',
|
|
41
|
+
ok ? null : `${path.relative(root, entry)} never registers a background handler, so messages that arrive while the app is in the background or killed are not handled on Android.`,
|
|
42
|
+
ok ? null : `Add to ${path.relative(root, entry)}, above AppRegistry.registerComponent:\n import { registerBackgroundHandler } from 'rn-firebase-notifications-kit';\n registerBackgroundHandler();`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function checkAndroid(root, add) {
|
|
46
|
+
const app = path.join(root, 'android', 'app');
|
|
47
|
+
const servicesFile = path.join(app, 'google-services.json');
|
|
48
|
+
const services = read(servicesFile);
|
|
49
|
+
add('android-services', services ? 'pass' : 'fail', 'android/app/google-services.json exists',
|
|
50
|
+
services ? null : 'Firebase cannot start on Android without it.',
|
|
51
|
+
services ? null : 'Firebase console โ Project settings โ your Android app โ download google-services.json into android/app/');
|
|
52
|
+
|
|
53
|
+
const appGradle = read(path.join(app, 'build.gradle')) ?? read(path.join(app, 'build.gradle.kts')) ?? '';
|
|
54
|
+
const rootGradle = read(path.join(root, 'android', 'build.gradle')) ?? read(path.join(root, 'android', 'build.gradle.kts')) ?? '';
|
|
55
|
+
|
|
56
|
+
if (services) {
|
|
57
|
+
let packages = [];
|
|
58
|
+
try {
|
|
59
|
+
packages = (JSON.parse(services).client || []).map((c) => c?.client_info?.android_client_info?.package_name).filter(Boolean);
|
|
60
|
+
} catch { /* reported below */ }
|
|
61
|
+
const appId = appGradle.match(/applicationId\s*=?\s*["']([^"']+)["']/)?.[1];
|
|
62
|
+
if (!packages.length) {
|
|
63
|
+
add('android-package', 'fail', 'google-services.json matches the app id', 'google-services.json could not be read as JSON or lists no Android apps.', 'Download a fresh copy from the Firebase console.');
|
|
64
|
+
} else if (!appId) {
|
|
65
|
+
add('android-package', 'warn', 'google-services.json matches the app id', 'Could not read applicationId from android/app/build.gradle, so the match was not checked.', null);
|
|
66
|
+
} else if (packages.includes(appId)) {
|
|
67
|
+
add('android-package', 'pass', 'google-services.json matches the app id', null, null);
|
|
68
|
+
} else {
|
|
69
|
+
const flavored = /applicationIdSuffix/.test(appGradle);
|
|
70
|
+
add('android-package', flavored ? 'warn' : 'fail', 'google-services.json matches the app id',
|
|
71
|
+
`applicationId is "${appId}" but google-services.json is for: ${packages.join(', ')}.${flavored ? ' The build uses applicationIdSuffix, so a variant may still match.' : ''}`,
|
|
72
|
+
'Add this app id to the Firebase project and download google-services.json again.');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const pluginId = 'com.google.gms.google-services';
|
|
77
|
+
const applied = appGradle.includes(pluginId);
|
|
78
|
+
const declared = rootGradle.includes('com.google.gms:google-services') || rootGradle.includes(pluginId);
|
|
79
|
+
add('android-plugin', applied && declared ? 'pass' : 'fail', 'Google services Gradle plugin is applied',
|
|
80
|
+
applied && declared ? null : [!declared && 'not declared in android/build.gradle', !applied && 'not applied in android/app/build.gradle'].filter(Boolean).join('; '),
|
|
81
|
+
applied && declared ? null : "android/build.gradle โ classpath 'com.google.gms:google-services:<version>'\nandroid/app/build.gradle โ apply plugin: 'com.google.gms.google-services'");
|
|
82
|
+
|
|
83
|
+
const manifest = read(path.join(app, 'src', 'main', 'AndroidManifest.xml'));
|
|
84
|
+
if (manifest !== null) {
|
|
85
|
+
const declaredPermission = manifest.includes('android.permission.POST_NOTIFICATIONS');
|
|
86
|
+
add('android-permission', declaredPermission ? 'pass' : 'warn', 'POST_NOTIFICATIONS permission is declared',
|
|
87
|
+
declaredPermission ? null : 'Not declared in your AndroidManifest.xml. A library may add it at build time; if the permission prompt never appears on Android 13+, this is why.',
|
|
88
|
+
declaredPermission ? null : '<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function checkIos(root, add) {
|
|
93
|
+
const ios = path.join(root, 'ios');
|
|
94
|
+
const plist = findFiles(ios, (name) => name === 'GoogleService-Info.plist');
|
|
95
|
+
add('ios-services', plist.length ? 'pass' : 'fail', 'GoogleService-Info.plist exists',
|
|
96
|
+
plist.length ? null : 'Firebase cannot start on iOS without it.',
|
|
97
|
+
plist.length ? null : 'Firebase console โ Project settings โ your iOS app โ download GoogleService-Info.plist and add it to the Xcode target.');
|
|
98
|
+
|
|
99
|
+
const entitlements = findFiles(ios, (name) => name.endsWith('.entitlements'));
|
|
100
|
+
const hasAps = entitlements.some((file) => (read(file) || '').includes('aps-environment'));
|
|
101
|
+
add('ios-capability', hasAps ? 'pass' : 'fail', 'Push Notifications capability is enabled',
|
|
102
|
+
hasAps ? null : 'No .entitlements file contains aps-environment, so APNs will not issue a device token.',
|
|
103
|
+
hasAps ? null : 'Xcode โ target โ Signing & Capabilities โ + Capability โ Push Notifications');
|
|
104
|
+
|
|
105
|
+
const infoPlists = findFiles(ios, (name) => name === 'Info.plist').filter((file) => !/Tests?[\\/]/.test(file));
|
|
106
|
+
const hasBackgroundMode = infoPlists.some((file) => /UIBackgroundModes[\s\S]*?remote-notification/.test(read(file) || ''));
|
|
107
|
+
add('ios-background', hasBackgroundMode ? 'pass' : 'warn', 'Remote notifications background mode is on',
|
|
108
|
+
hasBackgroundMode ? null : 'Without it iOS does not wake the app for data-only (silent) messages.',
|
|
109
|
+
hasBackgroundMode ? null : 'Xcode โ Signing & Capabilities โ Background Modes โ Remote notifications');
|
|
110
|
+
|
|
111
|
+
const delegates = findFiles(ios, (name) => /^AppDelegate\.(swift|mm|m)$/.test(name));
|
|
112
|
+
const configured = delegates.some((file) => /FirebaseApp\.configure\(\)|\[FIRApp configure\]/.test(read(file) || ''));
|
|
113
|
+
add('ios-configure', configured ? 'pass' : (delegates.length ? 'fail' : 'warn'), 'Firebase is configured in AppDelegate',
|
|
114
|
+
configured ? null : (delegates.length ? 'AppDelegate never calls FirebaseApp.configure().' : 'Could not find AppDelegate to check.'),
|
|
115
|
+
configured ? null : 'Add FirebaseApp.configure() (Swift) or [FIRApp configure]; (Objective-C) at the start of didFinishLaunchingWithOptions.');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function checkExpoManaged(root, add) {
|
|
119
|
+
const raw = read(path.join(root, 'app.json'));
|
|
120
|
+
if (!raw) {
|
|
121
|
+
add('expo', 'warn', 'Expo config is set up for Firebase', 'No android/ or ios/ folder and no static app.json, so native setup could not be checked (dynamic app.config.js is not evaluated).', null);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
let expo = null;
|
|
125
|
+
try { expo = JSON.parse(raw).expo; } catch { /* handled below */ }
|
|
126
|
+
if (!expo) { add('expo', 'warn', 'Expo config is set up for Firebase', 'app.json has no "expo" section.', null); return; }
|
|
127
|
+
const plugins = (expo.plugins || []).map((p) => (Array.isArray(p) ? p[0] : p));
|
|
128
|
+
const hasPlugin = plugins.includes('@react-native-firebase/app');
|
|
129
|
+
add('expo-plugin', hasPlugin ? 'pass' : 'fail', '@react-native-firebase/app config plugin is listed',
|
|
130
|
+
hasPlugin ? null : 'Without the plugin, prebuild does not wire Firebase into the native projects.',
|
|
131
|
+
hasPlugin ? null : 'app.json โ expo.plugins โ add "@react-native-firebase/app"');
|
|
132
|
+
const android = Boolean(expo.android?.googleServicesFile);
|
|
133
|
+
const ios = Boolean(expo.ios?.googleServicesFile);
|
|
134
|
+
add('expo-services', android && ios ? 'pass' : 'fail', 'googleServicesFile is set for Android and iOS',
|
|
135
|
+
android && ios ? null : `Missing for: ${[!android && 'android', !ios && 'ios'].filter(Boolean).join(', ')}`,
|
|
136
|
+
android && ios ? null : 'app.json โ expo.android.googleServicesFile: "./google-services.json", expo.ios.googleServicesFile: "./GoogleService-Info.plist"');
|
|
137
|
+
add('expo-go', 'warn', 'Runs in a development build, not Expo Go', 'Firebase Messaging and Notifee contain native code, which Expo Go does not include.', 'npx expo prebuild, or build a development client with EAS.');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Inspect a React Native project folder. Returns { checks, summary } and never throws for a missing file. */
|
|
141
|
+
export function runDoctor(projectDir) {
|
|
142
|
+
const root = path.resolve(projectDir);
|
|
143
|
+
const pkgRaw = read(path.join(root, 'package.json'));
|
|
144
|
+
if (!pkgRaw) throw new Error(`No package.json in ${root}. Run this from your React Native project root, or pass the path.`);
|
|
145
|
+
let pkg;
|
|
146
|
+
try { pkg = JSON.parse(pkgRaw); } catch { throw new Error(`package.json in ${root} is not valid JSON.`); }
|
|
147
|
+
|
|
148
|
+
const checks = [];
|
|
149
|
+
const add = (id, status, title, detail, fix) => checks.push({ id, status, title, detail, fix });
|
|
150
|
+
|
|
151
|
+
checkJs(root, pkg, add);
|
|
152
|
+
const hasAndroid = exists(path.join(root, 'android'));
|
|
153
|
+
const hasIos = exists(path.join(root, 'ios'));
|
|
154
|
+
if (hasAndroid) checkAndroid(root, add);
|
|
155
|
+
if (hasIos) checkIos(root, add);
|
|
156
|
+
if (!hasAndroid && !hasIos) checkExpoManaged(root, add);
|
|
157
|
+
|
|
158
|
+
const count = (status) => checks.filter((c) => c.status === status).length;
|
|
159
|
+
return { root, checks, summary: { passed: count('pass'), failed: count('fail'), warnings: count('warn') } };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function formatReport({ root, checks, summary }) {
|
|
163
|
+
const mark = { pass: 'โ', fail: 'โ', warn: '!' };
|
|
164
|
+
const lines = [`rn-firebase-notifications-kit doctor ยท ${root}`, ''];
|
|
165
|
+
for (const check of checks) {
|
|
166
|
+
lines.push(`${mark[check.status]} ${check.title}`);
|
|
167
|
+
if (check.detail) lines.push(` ${check.detail}`);
|
|
168
|
+
if (check.fix) lines.push(...check.fix.split('\n').map((line, i) => ` ${i === 0 ? 'fix: ' : ' '}${line}`));
|
|
169
|
+
}
|
|
170
|
+
lines.push('', `${summary.passed} passed ยท ${summary.failed} failed ยท ${summary.warnings} warning${summary.warnings === 1 ? '' : 's'}`);
|
|
171
|
+
if (summary.failed === 0) lines.push('Files look right. This cannot check your Firebase console or APNs key, so send a test message to confirm.');
|
|
172
|
+
return lines.join('\n');
|
|
173
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
export interface PushNotification {
|
|
2
|
+
/** FCM message id, or `data.id` when the message has none. */
|
|
3
|
+
id: string | null;
|
|
4
|
+
title: string | null;
|
|
5
|
+
body: string | null;
|
|
6
|
+
data: Record<string, string>;
|
|
7
|
+
/** Channel the message asked for (`data.channelId`), if any. */
|
|
8
|
+
channelId: string | null;
|
|
9
|
+
/** True when FCM sent a `notification` payload (the OS shows these itself in background / killed state). */
|
|
10
|
+
hasNotificationPayload: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface PushChannel {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
/** Default 'high'. A Notifee AndroidImportance number is also accepted. */
|
|
18
|
+
importance?: 'min' | 'low' | 'default' | 'high' | number;
|
|
19
|
+
/** Sound file name in android/app/src/main/res/raw, without the extension. */
|
|
20
|
+
sound?: string;
|
|
21
|
+
vibration?: boolean;
|
|
22
|
+
/** Android small icon resource name for this channel, e.g. `ic_chat`. */
|
|
23
|
+
smallIcon?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface PushConfig {
|
|
27
|
+
/** Android channels. The first one is the default unless `defaultChannel` is set. Define them once, in index.js. */
|
|
28
|
+
channels?: PushChannel[];
|
|
29
|
+
defaultChannel?: string;
|
|
30
|
+
/** Android small icon resource name used when a channel sets none. */
|
|
31
|
+
smallIcon?: string;
|
|
32
|
+
/** Android accent colour, e.g. '#17BE00'. */
|
|
33
|
+
color?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Change the Notifee payload before a notification is displayed (add an image, actions, a style).
|
|
36
|
+
* Return the new payload, or nothing to keep the original.
|
|
37
|
+
*/
|
|
38
|
+
decorate?: (notification: PushNotification, payload: Record<string, any>) => Record<string, any> | void | Promise<Record<string, any> | void>;
|
|
39
|
+
/** Receives every Notifee event (action presses, dismissals, ...) in foreground and background. */
|
|
40
|
+
onEvent?: (event: { type: number; detail: Record<string, any> }, info: { state: 'foreground' | 'background'; notification: PushNotification | null }) => void | Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type AppState = 'foreground' | 'background' | 'quit';
|
|
44
|
+
|
|
45
|
+
export interface BackgroundHandlerOptions extends PushConfig {
|
|
46
|
+
/** Show data-only messages as notifications. Default true. */
|
|
47
|
+
display?: boolean;
|
|
48
|
+
/** Runs for every background / killed-state message, before it is displayed. */
|
|
49
|
+
onMessage?: (notification: PushNotification, remoteMessage: unknown) => void | Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface NavigationRefLike {
|
|
53
|
+
isReady(): boolean;
|
|
54
|
+
navigate(name: string, params?: object): void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface Route {
|
|
58
|
+
name: string;
|
|
59
|
+
params?: object;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type PermissionStatus = 'granted' | 'provisional' | 'denied' | 'blocked' | 'undetermined';
|
|
63
|
+
|
|
64
|
+
export interface Permission {
|
|
65
|
+
status: PermissionStatus;
|
|
66
|
+
/** True for 'granted' and 'provisional'. */
|
|
67
|
+
granted: boolean;
|
|
68
|
+
/** False when the OS will not show the prompt again; send the user to `openSettings()` instead. */
|
|
69
|
+
canAsk: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** iOS prompt options. Ignored on Android. */
|
|
73
|
+
export interface IosPermissionOptions {
|
|
74
|
+
alert?: boolean;
|
|
75
|
+
badge?: boolean;
|
|
76
|
+
sound?: boolean;
|
|
77
|
+
/** Deliver quietly to Notification Center without showing a prompt. */
|
|
78
|
+
provisional?: boolean;
|
|
79
|
+
/** Needs a special entitlement from Apple. */
|
|
80
|
+
criticalAlert?: boolean;
|
|
81
|
+
carPlay?: boolean;
|
|
82
|
+
announcement?: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface SetupPushOptions extends PushConfig {
|
|
86
|
+
/** A message arrived while the app is in the foreground. */
|
|
87
|
+
onNotification?: (notification: PushNotification, remoteMessage: unknown) => void;
|
|
88
|
+
/** The user tapped a notification. Return `false` to skip automatic navigation for this tap. */
|
|
89
|
+
onOpen?: (notification: PushNotification, info: { state: AppState }) => void | boolean;
|
|
90
|
+
/** Called with the FCM token now and whenever it refreshes. */
|
|
91
|
+
onToken?: (token: string) => void;
|
|
92
|
+
onError?: (error: unknown) => void;
|
|
93
|
+
/** React Navigation container ref. When set, a tap opens `data.screen` with `data.params`. */
|
|
94
|
+
navigationRef?: NavigationRefLike;
|
|
95
|
+
/** Map a tapped notification to a route. Return null to stay where you are. */
|
|
96
|
+
resolveRoute?: (notification: PushNotification, info: { state: AppState }) => Route | null;
|
|
97
|
+
/** true (default) asks now; false only reads the current state; an object passes iOS options. */
|
|
98
|
+
requestPermission?: boolean | IosPermissionOptions;
|
|
99
|
+
/** Show a notification for foreground messages. Default true. */
|
|
100
|
+
showInForeground?: boolean;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface SetupPushResult {
|
|
104
|
+
granted: boolean;
|
|
105
|
+
permission: Permission;
|
|
106
|
+
token: string | null;
|
|
107
|
+
unsubscribe(): void;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface Restrictions {
|
|
111
|
+
/** Android battery optimisation is on for this app; background delivery may be delayed. */
|
|
112
|
+
batteryOptimized: boolean;
|
|
113
|
+
/** Set on phones with their own background-app killer (Xiaomi, Oppo, Vivo, Huawei, ...). */
|
|
114
|
+
powerManager: { manufacturer: string | null; model: string | null } | null;
|
|
115
|
+
/** Configured channels the user has switched off. */
|
|
116
|
+
blockedChannels: string[];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export const DEFAULT_CHANNEL: PushChannel;
|
|
120
|
+
export function registerBackgroundHandler(options?: BackgroundHandlerOptions): void;
|
|
121
|
+
export function setupPush(options?: SetupPushOptions): Promise<SetupPushResult>;
|
|
122
|
+
export function getPermission(): Promise<Permission>;
|
|
123
|
+
export function requestPermission(options?: IosPermissionOptions): Promise<Permission>;
|
|
124
|
+
export function openSettings(channelId?: string): Promise<void>;
|
|
125
|
+
export function getRestrictions(): Promise<Restrictions>;
|
|
126
|
+
export function openBatterySettings(): Promise<void>;
|
|
127
|
+
export function openPowerManagerSettings(): Promise<void>;
|
|
128
|
+
export function normalizeRemoteMessage(remoteMessage: unknown): PushNotification;
|
|
129
|
+
export function defaultResolveRoute(notification: PushNotification): Route | null;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as fm from '@react-native-firebase/messaging';
|
|
2
|
+
import notifee, { EventType, AndroidImportance, AuthorizationStatus } from '@notifee/react-native';
|
|
3
|
+
import { Platform, PermissionsAndroid } from 'react-native';
|
|
4
|
+
import { createPushKit } from './core.js';
|
|
5
|
+
|
|
6
|
+
const kit = createPushKit({
|
|
7
|
+
fm,
|
|
8
|
+
notifee,
|
|
9
|
+
EventType,
|
|
10
|
+
AndroidImportance,
|
|
11
|
+
AuthorizationStatus,
|
|
12
|
+
platform: Platform.OS,
|
|
13
|
+
apiLevel: Platform.Version,
|
|
14
|
+
PermissionsAndroid,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const {
|
|
18
|
+
registerBackgroundHandler,
|
|
19
|
+
setupPush,
|
|
20
|
+
getPermission,
|
|
21
|
+
requestPermission,
|
|
22
|
+
openSettings,
|
|
23
|
+
getRestrictions,
|
|
24
|
+
openBatterySettings,
|
|
25
|
+
openPowerManagerSettings,
|
|
26
|
+
} = kit;
|
|
27
|
+
export { normalizeRemoteMessage, defaultResolveRoute, DEFAULT_CHANNEL } from './core.js';
|