Complete the code to import the Firebase messaging module in React Native.
import messaging from '[1]';
The correct import for Firebase Cloud Messaging in React Native is @react-native-firebase/messaging.
Complete the code to request user permission for push notifications.
const authStatus = await messaging().[1]();To ask the user for permission to receive push notifications, use requestPermission().
Fix the error in the code to get the FCM token correctly.
const fcmToken = await messaging().[1]();The method getToken() retrieves the device's FCM token needed for push notifications.
Fill both blanks to listen for incoming messages when the app is in the foreground.
useEffect(() => {
const unsubscribe = messaging().[1](remoteMessage => {
console.log('Message received:', remoteMessage.[2]);
});
return unsubscribe;
}, []);Use onMessage to listen for messages, and access the notification property to get the message content.
Fill in the blank to subscribe to a topic and handle token refresh.
useEffect(() => {
messaging().[1]('news');
const unsubscribe = messaging().onTokenRefresh(token => {
console.log('New token:', token);
});
return unsubscribe;
}, []);Use subscribeToTopic to subscribe the device to a topic like 'news'.