FirebaseMessagingAdapter
Notification adapter for Firebase Cloud Messaging.
The FirebaseMessagingAdapter integrates with Firebase Cloud Messaging for push notifications.
Installation
npm install @react-native-firebase/app @react-native-firebase/messaging
# or
bun add @react-native-firebase/app @react-native-firebase/messagingFor iOS:
cd ios && pod installUsage
import { FirebaseMessagingAdapter } from '@teardown/react-native/firebase-messaging';
const notifications = new FirebaseMessagingAdapter();
// Request permissions (iOS)
const granted = await notifications.requestPermissions();
if (granted) {
// Get FCM token
const token = await notifications.getToken();
console.log('FCM token:', token);
}Import Path
import { FirebaseMessagingAdapter } from '@teardown/react-native/firebase-messaging';API
getToken()
Get the FCM registration token:
const token = await notifications.getToken();
// Returns: FCM token string or nullrequestPermissions()
Request notification permissions (required on iOS):
const granted = await notifications.requestPermissions();
// Returns: true if granted, false otherwiseisEnabled()
Check if notifications are enabled:
const enabled = await notifications.isEnabled();onNotification()
Subscribe to incoming notifications:
const unsubscribe = notifications.onNotification((notification) => {
console.log('Received:', notification.title);
});
// Cleanup
unsubscribe();onNotificationResponse()
Subscribe to notification opens:
const unsubscribe = notifications.onNotificationResponse((response) => {
console.log('User tapped:', response.notification.title);
});
// Cleanup
unsubscribe();Configuration
Android
- Add
google-services.jsontoandroid/app/ - Add to
android/build.gradle:
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
}
}- Add to
android/app/build.gradle:
apply plugin: 'com.google.gms.google-services'iOS
- Add
GoogleService-Info.plistto iOS project - Enable Push Notifications capability in Xcode
- Upload APNs key to Firebase Console
Background Messages
Handle messages when app is in background:
import messaging from '@react-native-firebase/messaging';
// Register background handler (must be outside component)
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Background message:', remoteMessage);
});Requirements
@react-native-firebase/app>= 18.0.0@react-native-firebase/messaging>= 18.0.0- React Native >= 0.71