Skip to content

Commit 7db79f5

Browse files
committed
Add more comments and a note.
1 parent f86cf42 commit 7db79f5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/pages/docs/push/getting-started/react-native.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ Push notification activation in React Native requires obtaining an FCM registrat
239239

240240
<Code>
241241
```react
242+
// Generate a unique device ID for this installation
242243
const [deviceId] = useState(
243244
`push-tutorial-${Platform.OS}-${Math.random().toString(36).slice(2, 9)}`,
244245
);
@@ -250,13 +251,15 @@ async function requestPermission(): Promise<boolean> {
250251
const settings = await notifee.requestPermission();
251252
return settings.authorizationStatus >= AuthorizationStatus.AUTHORIZED;
252253
}
254+
// On iOS, request permission using Firebase Messaging which will trigger the native iOS permission dialog
253255
const authStatus = await messaging().requestPermission();
254256
return (
255257
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
256258
authStatus === messaging.AuthorizationStatus.PROVISIONAL
257259
);
258260
}
259261
262+
// Save the device registration with Ably using the FCM token
260263
async function saveDeviceRegistration(token: string) {
261264
await realtime.push.admin.deviceRegistrations.save({
262265
id: deviceId,
@@ -329,6 +332,10 @@ After successful activation, `deviceId` contains the unique device ID assigned t
329332
On Android, use `notifee.requestPermission()` instead of React Native's `PermissionsAndroid` because it handles the `POST_NOTIFICATIONS` permission consistently across Android API levels. On iOS, `messaging().requestPermission()` shows the system notification permission dialog; Firebase Messaging calls the native iOS permission APIs internally.
330333
</Aside>
331334

335+
<Aside data-type='note'>
336+
In React Native `realtime.push.activate()` is not used because it's a JS SDK and it registers browser for push notifications, which is not what we want in a React Native app. Instead, `realtime.push.admin.deviceRegistrations` API is used to register the device.
337+
</Aside>
338+
332339
## Step 3: Subscribe and test push notifications <a id="step-3"/>
333340

334341
The FCM SDK handles background push notifications automatically and displays them as system notifications. For foreground handling, use `@notifee/react-native` to display notifications while the app is open.

0 commit comments

Comments
 (0)