From 8d6a8b440b779f99185715636aba441be1ac874d Mon Sep 17 00:00:00 2001 From: wanxiankai Date: Mon, 13 Jul 2026 08:44:18 +0800 Subject: [PATCH 1/3] docs(messaging): update token registration examples --- docs/messaging/notifications.mdx | 13 +++++++------ packages/app/firebase-schema.json | 2 +- .../ios/RNFBMessaging/RNFBMessagingModule.mm | 6 ++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/messaging/notifications.mdx b/docs/messaging/notifications.mdx index c42b4a1172..3e3d4edeeb 100644 --- a/docs/messaging/notifications.mdx +++ b/docs/messaging/notifications.mdx @@ -207,15 +207,16 @@ function App() { To send messages to a device, you would need the FCM token for it, which you can get using the `getToken(messaging)` method. An example is available on '[Notifee pages](https://notifee.app/react-native/docs/integrations/fcm)'. +On iOS, React Native Firebase Messaging automatically registers the device with APNs by default. You only need to +manually call `registerDeviceForRemoteMessages(messaging)` before `getToken(messaging)` if you disabled +auto-registration with `messaging_ios_auto_register_for_remote_messages` in `firebase.json`, or if you otherwise call +`getToken(messaging)` before the app has registered for remote messages. See +[Auto Registration (iOS)](/messaging/usage#auto-registration-ios) for the manual registration example. + ```jsx -import { - getMessaging, - registerDeviceForRemoteMessages, - getToken, -} from '@react-native-firebase/messaging'; +import { getMessaging, getToken } from '@react-native-firebase/messaging'; const messaging = getMessaging(); -await registerDeviceForRemoteMessages(messaging); const token = await getToken(messaging); // save the token to the db ``` diff --git a/packages/app/firebase-schema.json b/packages/app/firebase-schema.json index 3733edd956..1711fd338a 100644 --- a/packages/app/firebase-schema.json +++ b/packages/app/firebase-schema.json @@ -112,7 +112,7 @@ "type": "string" }, "messaging_ios_auto_register_for_remote_messages": { - "description": "Whether RNFirebase Messaging automatically calls `[[UIApplication sharedApplication] registerForRemoteNotifications];`\nautomatically on app launch (recommended) - defaults to true.\n If set to false; make sure to call `firebase.messaging().registerDeviceForRemoteMessages()`\nearly on in your app startup - otherwise you will NOT receive remote messages/notifications\nin your app.\n", + "description": "Whether RNFirebase Messaging automatically calls `[[UIApplication sharedApplication] registerForRemoteNotifications];`\nautomatically on app launch (recommended) - defaults to true.\n If set to false; make sure to call `registerDeviceForRemoteMessages(getMessaging())`\nearly on in your app startup - otherwise you will NOT receive remote messages/notifications\nin your app.\n", "type": "boolean" }, "messaging_ios_foreground_presentation_options": { diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessagingModule.mm b/packages/messaging/ios/RNFBMessaging/RNFBMessagingModule.mm index 0cfe104c9c..cecddd854b 100644 --- a/packages/messaging/ios/RNFBMessaging/RNFBMessagingModule.mm +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessagingModule.mm @@ -131,8 +131,7 @@ - (void)getToken:(NSString *)appName @"message" : @"You must be registered for remote " @"messages before calling " @"getToken, see " - @"messaging()." - @"registerDeviceForRemoteMessages().", + @"registerDeviceForRemoteMessages(getMessaging()).", }]; return; } @@ -199,8 +198,7 @@ - (void)getAPNSToken:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlo @"message" : @"You must be registered for remote " @"messages before " @"calling getAPNSToken, see " - @"messaging()." - @"registerDeviceForRemoteMessages().", + @"registerDeviceForRemoteMessages(getMessaging()).", }]; return; } From 4e9af7f7f285ec589bf4344f5cb9867a14df726a Mon Sep 17 00:00:00 2001 From: wanxiankai Date: Mon, 13 Jul 2026 23:36:26 +0800 Subject: [PATCH 2/3] docs(messaging): address token registration review --- docs/messaging/notifications.mdx | 8 +++++++- packages/app/firebase-schema.json | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/messaging/notifications.mdx b/docs/messaging/notifications.mdx index 3e3d4edeeb..1d76291dbe 100644 --- a/docs/messaging/notifications.mdx +++ b/docs/messaging/notifications.mdx @@ -214,9 +214,15 @@ auto-registration with `messaging_ios_auto_register_for_remote_messages` in `fir [Auto Registration (iOS)](/messaging/usage#auto-registration-ios) for the manual registration example. ```jsx -import { getMessaging, getToken } from '@react-native-firebase/messaging'; +import { + getMessaging, + registerDeviceForRemoteMessages, + getToken, +} from '@react-native-firebase/messaging'; const messaging = getMessaging(); +// Optional: not needed in most cases, and a no-op if already registered. +await registerDeviceForRemoteMessages(messaging); const token = await getToken(messaging); // save the token to the db ``` diff --git a/packages/app/firebase-schema.json b/packages/app/firebase-schema.json index 1711fd338a..31896a46da 100644 --- a/packages/app/firebase-schema.json +++ b/packages/app/firebase-schema.json @@ -112,7 +112,7 @@ "type": "string" }, "messaging_ios_auto_register_for_remote_messages": { - "description": "Whether RNFirebase Messaging automatically calls `[[UIApplication sharedApplication] registerForRemoteNotifications];`\nautomatically on app launch (recommended) - defaults to true.\n If set to false; make sure to call `registerDeviceForRemoteMessages(getMessaging())`\nearly on in your app startup - otherwise you will NOT receive remote messages/notifications\nin your app.\n", + "description": "Whether RNFirebase Messaging automatically calls `[[UIApplication sharedApplication] registerForRemoteNotifications];`\non app launch (recommended) - defaults to true.\n If set to false, make sure to call `registerDeviceForRemoteMessages(getMessaging())`\nearly on in your app startup - otherwise you will NOT receive remote messages/notifications\nin your app.\n", "type": "boolean" }, "messaging_ios_foreground_presentation_options": { From 1c80bc28ee518d770662624689e4a90b6d239c43 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Fri, 17 Jul 2026 17:30:14 -0500 Subject: [PATCH 3/3] style(lint): fix iOS formatting after message update --- .../ios/RNFBMessaging/RNFBMessagingModule.mm | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessagingModule.mm b/packages/messaging/ios/RNFBMessaging/RNFBMessagingModule.mm index cecddd854b..228f2cdc77 100644 --- a/packages/messaging/ios/RNFBMessaging/RNFBMessagingModule.mm +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessagingModule.mm @@ -125,14 +125,15 @@ - (void)getToken:(NSString *)appName resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { if ([UIApplication sharedApplication].isRegisteredForRemoteNotifications == NO) { - [RNFBSharedUtils rejectPromiseWithUserInfo:reject - userInfo:(NSMutableDictionary *)@{ - @"code" : @"unregistered", - @"message" : @"You must be registered for remote " - @"messages before calling " - @"getToken, see " - @"registerDeviceForRemoteMessages(getMessaging()).", - }]; + [RNFBSharedUtils + rejectPromiseWithUserInfo:reject + userInfo:(NSMutableDictionary *)@{ + @"code" : @"unregistered", + @"message" : @"You must be registered for remote " + @"messages before calling " + @"getToken, see " + @"registerDeviceForRemoteMessages(getMessaging()).", + }]; return; } @@ -192,14 +193,15 @@ - (void)getAPNSToken:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlo @"Use setAPNSToken in testing if needed."); #endif if ([UIApplication sharedApplication].isRegisteredForRemoteNotifications == NO) { - [RNFBSharedUtils rejectPromiseWithUserInfo:reject - userInfo:(NSMutableDictionary *)@{ - @"code" : @"unregistered", - @"message" : @"You must be registered for remote " - @"messages before " - @"calling getAPNSToken, see " - @"registerDeviceForRemoteMessages(getMessaging()).", - }]; + [RNFBSharedUtils + rejectPromiseWithUserInfo:reject + userInfo:(NSMutableDictionary *)@{ + @"code" : @"unregistered", + @"message" : @"You must be registered for remote " + @"messages before " + @"calling getAPNSToken, see " + @"registerDeviceForRemoteMessages(getMessaging()).", + }]; return; } resolve([NSNull null]);