From 3c045779106f93b63888a0ab0dd874dae30807ea Mon Sep 17 00:00:00 2001 From: seth-jo Date: Thu, 30 Oct 2025 08:03:24 +0000 Subject: [PATCH 1/8] docs: update requestUserPermission example to modular --- docs/messaging/usage/index.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/messaging/usage/index.md b/docs/messaging/usage/index.md index 15bc09bf7b..737883eba5 100644 --- a/docs/messaging/usage/index.md +++ b/docs/messaging/usage/index.md @@ -95,13 +95,14 @@ iOS prevents messages containing notification (or 'alert') payloads from being d This module provides a `requestPermission` method which triggers a native permission dialog requesting the user's permission: ```js -import messaging from '@react-native-firebase/messaging'; +import {getMessaging, requestPermission, AuthorizationStatus} from '@react-native-firebase/messaging'; async function requestUserPermission() { - const authStatus = await messaging().requestPermission(); + const messaging = await getMessaging(); + const authStatus = await requestPermission(messaging); const enabled = - authStatus === messaging.AuthorizationStatus.AUTHORIZED || - authStatus === messaging.AuthorizationStatus.PROVISIONAL; + authStatus === AuthorizationStatus.AUTHORIZED || + authStatus === AuthorizationStatus.PROVISIONAL; if (enabled) { console.log('Authorization status:', authStatus); From e6b356e7ddae2604e13bd269883c4aa08c034587 Mon Sep 17 00:00:00 2001 From: seth-jo Date: Thu, 30 Oct 2025 08:06:38 +0000 Subject: [PATCH 2/8] docs: update onMessage example --- docs/messaging/usage/index.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/messaging/usage/index.md b/docs/messaging/usage/index.md index 737883eba5..387328dbd5 100644 --- a/docs/messaging/usage/index.md +++ b/docs/messaging/usage/index.md @@ -190,11 +190,12 @@ each time a message is delivered' ```js import React, { useEffect } from 'react'; import { Alert } from 'react-native'; -import messaging from '@react-native-firebase/messaging'; +import {getMessaging, onMessage} from '@react-native-firebase/messaging'; function App() { useEffect(() => { - const unsubscribe = messaging().onMessage(async remoteMessage => { + const messaging = await getMessaging(); + const unsubscribe = onMessage(messaging, async remoteMessage => { Alert.alert('A new FCM message arrived!', JSON.stringify(remoteMessage)); }); From 3a90e32cbe23a560286741bd08c3479791f99a7b Mon Sep 17 00:00:00 2001 From: seth-jo Date: Thu, 30 Oct 2025 08:13:58 +0000 Subject: [PATCH 3/8] docs: remove erroneous awaits I just added --- docs/messaging/usage/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/messaging/usage/index.md b/docs/messaging/usage/index.md index 387328dbd5..ed43420c97 100644 --- a/docs/messaging/usage/index.md +++ b/docs/messaging/usage/index.md @@ -98,7 +98,7 @@ This module provides a `requestPermission` method which triggers a native permis import {getMessaging, requestPermission, AuthorizationStatus} from '@react-native-firebase/messaging'; async function requestUserPermission() { - const messaging = await getMessaging(); + const messaging = getMessaging(); const authStatus = await requestPermission(messaging); const enabled = authStatus === AuthorizationStatus.AUTHORIZED || @@ -194,7 +194,7 @@ import {getMessaging, onMessage} from '@react-native-firebase/messaging'; function App() { useEffect(() => { - const messaging = await getMessaging(); + const messaging = getMessaging(); const unsubscribe = onMessage(messaging, async remoteMessage => { Alert.alert('A new FCM message arrived!', JSON.stringify(remoteMessage)); }); From 313ee29ecb21293b27b810c561589a8cb514b5b5 Mon Sep 17 00:00:00 2001 From: seth-jo Date: Thu, 30 Oct 2025 08:15:52 +0000 Subject: [PATCH 4/8] docs: update setBackgroundMessageHandler example for background to modular example --- docs/messaging/usage/index.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/messaging/usage/index.md b/docs/messaging/usage/index.md index ed43420c97..c564c4f933 100644 --- a/docs/messaging/usage/index.md +++ b/docs/messaging/usage/index.md @@ -224,11 +224,12 @@ To setup a background handler, call the `setBackgroundMessageHandler` outside of ```jsx // index.js import { AppRegistry } from 'react-native'; -import messaging from '@react-native-firebase/messaging'; +import {getMessaging, setBackgroundMessageHandler} from '@react-native-firebase/messaging'; import App from './App'; +const messaging = getMessaging(); // Register background handler -messaging().setBackgroundMessageHandler(async remoteMessage => { +setBackgroundMessageHandler(messaging, async remoteMessage => { console.log('Message handled in the background!', remoteMessage); }); From bd46bf11470b70b886ce04784347163a0f323b7d Mon Sep 17 00:00:00 2001 From: seth-jo Date: Thu, 30 Oct 2025 08:17:00 +0000 Subject: [PATCH 5/8] docs: update example for background application state to modular --- docs/messaging/usage/index.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/messaging/usage/index.md b/docs/messaging/usage/index.md index c564c4f933..bc1535732c 100644 --- a/docs/messaging/usage/index.md +++ b/docs/messaging/usage/index.md @@ -315,10 +315,12 @@ you can configure your `AppDelegate.m` file (see instructions below) to inject a ```jsx // index.js import { AppRegistry } from 'react-native'; -import messaging from '@react-native-firebase/messaging'; +import {getMessaging, setBackgroundMessageHandler} from '@react-native-firebase/messaging'; + +const messaging = getMessaging(); // Handle background messages using setBackgroundMessageHandler -messaging().setBackgroundMessageHandler(async remoteMessage => { +setBackgroundMessageHandler(messaging, async remoteMessage => { console.log('Message handled in the background!', remoteMessage); }); From b6884bd39efa9dcba019646781be924966e3c915 Mon Sep 17 00:00:00 2001 From: seth-jo Date: Thu, 30 Oct 2025 08:22:22 +0000 Subject: [PATCH 6/8] docs: update subscription method examples and auto registration to modular --- docs/messaging/usage/index.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/messaging/usage/index.md b/docs/messaging/usage/index.md index bc1535732c..6b762bb626 100644 --- a/docs/messaging/usage/index.md +++ b/docs/messaging/usage/index.md @@ -361,11 +361,10 @@ self.initialProps = [RNFBMessagingModule addCustomPropsToUserProps:nil withLaunc - For projects that use react-native-navigation (or if you just don't want to mess with your launchProperties) you can use the `getIsHeadless` method (iOS only) from messaging like so: ```jsx -messaging() - .getIsHeadless() - .then(isHeadless => { +const messaging = getMessaging(); +getIsHeadless(messaging).then(isHeadless => { // do sth with isHeadless - }); +}); ``` On Android, the `isHeadless` prop will not exist. @@ -401,8 +400,8 @@ documentation. To subscribe a device, call the `subscribeToTopic` method with the topic name (must not include "/"): ```js -messaging() - .subscribeToTopic('weather') +const messaging = getMessaging() +subscribeToTopic(messaging,'weather') .then(() => console.log('Subscribed to topic!')); ``` @@ -411,8 +410,8 @@ messaging() To unsubscribe from a topic, call the `unsubscribeFromTopic` method with the topic name: ```js -messaging() - .unsubscribeFromTopic('weather') +const messaging = getMessaging() +unsubscribeFromTopic(messaging,'weather') .then(() => console.log('Unsubscribed fom the topic!')); ``` @@ -438,10 +437,11 @@ Once auto-registration is disabled you must manually call `registerDeviceForRemo early as possible in your application startup; ```js -import messaging from '@react-native-firebase/messaging'; +import {getMessaging, registerDeviceForRemoteMessages} from '@react-native-firebase/messaging'; async function registerAppWithFCM() { - await messaging().registerDeviceForRemoteMessages(); + const messaging = getMessaging(); + await registerDeviceForRemoteMessages(messaging); } ``` From 43fdb824711e577c0c0d3e4f47c587dabde7d9b6 Mon Sep 17 00:00:00 2001 From: seth-jo Date: Thu, 30 Oct 2025 09:01:39 +0000 Subject: [PATCH 7/8] docs: Update the examples for the firebase-admin implementation to use the new modular format --- docs/messaging/usage/index.md | 41 +++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/docs/messaging/usage/index.md b/docs/messaging/usage/index.md index 6b762bb626..326231982a 100644 --- a/docs/messaging/usage/index.md +++ b/docs/messaging/usage/index.md @@ -254,28 +254,39 @@ handler, you must set the "priority" to "high" on Android, and enable the `conte if using the Node.js [`firebase-admin`](https://www.npmjs.com/package/firebase-admin) package to send a message: ```js -admin.messaging().sendToDevice( - [], // device fcm tokens... - { - data: { - owner: JSON.stringify(owner), - user: JSON.stringify(user), - picture: JSON.stringify(picture), + +const message = { + data: { + owner: JSON.stringify(owner), + user: JSON.stringify(user), + picture: JSON.stringify(picture), + }, + // device token + token: 'YOUR_DEVICE_TOKEN', + // Required for background/quit data-only messages on iOS + apns: { + headers: { + 'apns-priority': '5', + }, + payload: { + aps: { + contentAvailable: true, + }, }, }, - { - // Required for background/quit data-only messages on iOS - contentAvailable: true, - // Required for background/quit data-only messages on Android + // Required for background/quit data-only messages on Android + android: { priority: 'high', }, -); +}; + +getMessaging().send(message); ``` For iOS specific "data-only" messages, the message must include the appropriate APNs headers as well as the `content-available` flag in order to trigger the background handler. For example, if using the Node.js [`firebase-admin`](https://www.npmjs.com/package/firebase-admin) package to send a "data-only" message to an iOS device: ```js -admin.messaging().send({ +const message = { data: { //some data }, @@ -295,7 +306,9 @@ admin.messaging().send({ //token: //device token //topic: //notification topic //condition: //notification condition -}); +} + +getMessaging().send(message); ``` View the [Sending Notification Requests to APNs](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns/) documentation to learn more about APNs headers. From 28ec8b4858f1fa4f2aa67b24afabec3eb39473b6 Mon Sep 17 00:00:00 2001 From: seth-jo Date: Fri, 31 Oct 2025 20:46:41 +0000 Subject: [PATCH 8/8] docs: remove bad comment --- docs/messaging/usage/index.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/messaging/usage/index.md b/docs/messaging/usage/index.md index 326231982a..75b58cc9de 100644 --- a/docs/messaging/usage/index.md +++ b/docs/messaging/usage/index.md @@ -254,14 +254,12 @@ handler, you must set the "priority" to "high" on Android, and enable the `conte if using the Node.js [`firebase-admin`](https://www.npmjs.com/package/firebase-admin) package to send a message: ```js - const message = { data: { owner: JSON.stringify(owner), user: JSON.stringify(user), picture: JSON.stringify(picture), }, - // device token token: 'YOUR_DEVICE_TOKEN', // Required for background/quit data-only messages on iOS apns: {