FCM stands for Firebase Cloud Messaging. It is a service that helps send push notifications to mobile apps.
Click to reveal answer
beginner
Why do we need to ask user permission for push notifications on iOS?
iOS requires apps to ask users for permission before sending push notifications to respect user privacy and control.
Click to reveal answer
intermediate
What is the role of a device token in FCM push notifications?
A device token is a unique ID that identifies a device to FCM so it knows where to send the notification.
Click to reveal answer
intermediate
Name one React Native library commonly used to handle FCM push notifications.
One popular library is '@react-native-firebase/messaging' which helps integrate FCM in React Native apps.
Click to reveal answer
beginner
What is a common step to test push notifications during development?
You can use Firebase Console to send test notifications to your app using the device token.
Click to reveal answer
What is the first step to receive push notifications in a React Native app using FCM?
ARequest user permission for notifications
BSend a notification from Firebase Console
CInstall a React Native navigation library
DCreate a new Firebase project
✗ Incorrect
You must first ask the user for permission to receive notifications before you can get a device token.
Which platform requires explicit user permission for push notifications?
AAndroid
BiOS
CBoth Android and iOS
DNeither Android nor iOS
✗ Incorrect
iOS requires explicit user permission, while Android grants it by default.
What does the device token represent in FCM?
AApp version number
BUser's email address
CUnique device identifier for sending notifications
DFirebase project ID
✗ Incorrect
The device token uniquely identifies the device to receive push notifications.
Which React Native package is commonly used to handle FCM messaging?
Areact-navigation
Baxios
Credux
D@react-native-firebase/messaging
✗ Incorrect
The '@react-native-firebase/messaging' package helps integrate FCM push notifications.
Where can you send test push notifications to your app during development?
AFirebase Console
BGoogle Play Store
CApp Store Connect
DReact Native CLI
✗ Incorrect
Firebase Console allows you to send test notifications to your app using device tokens.
Explain the process of setting up push notifications with FCM in a React Native app.
Think about the steps from Firebase setup to receiving a notification on the device.
You got /5 concepts.
Describe why user permission is important for push notifications and how it differs between iOS and Android.
Consider platform rules and user control over notifications.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of Firebase Cloud Messaging (FCM) in a React Native app?
easy
A. To create UI components
B. To store user data locally
C. To send push notifications to the app users
D. To manage app navigation
Solution
Step 1: Understand FCM's role
FCM is a service designed to send push notifications to apps.
Step 2: Compare options
Only To send push notifications to the app users describes sending push notifications, which is FCM's main purpose.
Final Answer:
To send push notifications to the app users -> Option C
Quick Check:
FCM = Push notifications [OK]
Hint: FCM is about messaging, not UI or storage [OK]
Common Mistakes:
Confusing FCM with local data storage
Thinking FCM manages UI or navigation
Assuming FCM is for database operations
2. Which React Native Firebase method is used to get the device token for FCM push notifications?
easy
A. messaging().requestPermission()
B. messaging().getToken()
C. messaging().sendMessage()
D. messaging().subscribeToTopic()
Solution
Step 1: Identify token retrieval method
The method to get the device token is messaging().getToken().
Step 2: Eliminate other options
requestPermission() asks user permission, sendMessage() sends messages, subscribeToTopic() subscribes to topics.
Final Answer:
messaging().getToken() -> Option B
Quick Check:
Get token = getToken() [OK]
Hint: Get token with getToken(), not requestPermission() [OK]
Common Mistakes:
Using requestPermission() to get token
Confusing sendMessage() with token retrieval
Mixing subscribeToTopic() with token methods
3. What will be the output of this code snippet in a React Native app using FCM?
import messaging from '@react-native-firebase/messaging';
async function getToken() {
const token = await messaging().getToken();
console.log(token);
}
getToken();
medium
A. Logs the device's FCM token string to the console
B. Throws a syntax error due to missing await
C. Logs 'undefined' because getToken() returns nothing
D. Throws a runtime error because messaging() is undefined
Solution
Step 1: Analyze async function behavior
The function awaits messaging().getToken(), which returns the device token string.
Step 2: Understand console.log output
It logs the token string, not undefined or error, assuming messaging is imported correctly.
Final Answer:
Logs the device's FCM token string to the console -> Option A
Quick Check:
getToken() returns token string [OK]
Hint: Await getToken() to get token string, then log it [OK]
Common Mistakes:
Forgetting await causing Promise logged
Assuming getToken() returns undefined
Not importing messaging correctly
4. You wrote this code to request permission for notifications but it doesn't work as expected:
import messaging from '@react-native-firebase/messaging';
messaging().requestPermission();
What is the likely problem?
medium
A. requestPermission() is not a valid method
B. You need to import notifications instead of messaging
C. You must call getToken() before requestPermission()
D. You forgot to await the requestPermission() call
Solution
Step 1: Check async method usage
requestPermission() returns a Promise and should be awaited to complete permission request.
Step 2: Identify missing await effect
Without await, the permission request may not finish before next steps, causing unexpected behavior.
Final Answer:
You forgot to await the requestPermission() call -> Option D
Quick Check:
Await async calls like requestPermission() [OK]
Hint: Always await async permission requests [OK]
Common Mistakes:
Not awaiting async permission calls
Thinking requestPermission() is invalid
Calling getToken() before permission
5. You want to send a push notification only if the user has granted permission. Which code snippet correctly checks permission and then gets the FCM token in React Native?
hard
A. const authStatus = await messaging().requestPermission();
if (authStatus === messaging.AuthorizationStatus.AUTHORIZED) {
const token = await messaging().getToken();
console.log(token);
}
B. const token = await messaging().getToken();
if (token) {
await messaging().requestPermission();
console.log(token);
}
C. await messaging().getToken();
await messaging().requestPermission();
console.log('Permission and token done');
D. messaging().requestPermission();
messaging().getToken();
console.log('Permissions requested and token fetched');
Solution
Step 1: Check permission before token
const authStatus = await messaging().requestPermission();
if (authStatus === messaging.AuthorizationStatus.AUTHORIZED) {
const token = await messaging().getToken();
console.log(token);
} requests permission and checks if authorized before getting token.
Step 2: Verify async and order correctness
const authStatus = await messaging().requestPermission();
if (authStatus === messaging.AuthorizationStatus.AUTHORIZED) {
const token = await messaging().getToken();
console.log(token);
} awaits both calls and uses correct AuthorizationStatus check.
Final Answer:
const authStatus = await messaging().requestPermission();
if (authStatus === messaging.AuthorizationStatus.AUTHORIZED) {
const token = await messaging().getToken();
console.log(token);
} -> Option A
Quick Check:
Check permission first, then get token [OK]
Hint: Request permission first, then get token if authorized [OK]
Common Mistakes:
Getting token before permission
Not awaiting async calls
Ignoring authorization status check
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.