0
0
Firebasecloud~10 mins

FCM setup in Firebase - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - FCM setup
Create Firebase Project
Enable Cloud Messaging
Download config file
Add config to app
Initialize Firebase in app
Request user permission
Get FCM token
Send/Receive messages
This flow shows the steps to set up Firebase Cloud Messaging from project creation to sending and receiving messages.
Execution Sample
Firebase
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
messaging.requestPermission()
  .then(() => messaging.getToken())
  .then(token => console.log(token));
This code initializes Firebase, requests permission for notifications, and retrieves the FCM token.
Process Table
StepActionResultNext Step
1Initialize Firebase with configFirebase app readyRequest permission
2Request notification permissionPermission grantedGet FCM token
3Get FCM tokenToken received: abc123Use token to send messages
4Use token to send messageMessage sent successfullyListen for messages
5Receive messageMessage displayed to userEnd
6Permission denied or errorNo token receivedStop setup
💡 Setup ends after receiving token and sending/receiving messages or if permission denied.
Status Tracker
VariableStartAfter Step 2After Step 3Final
firebaseAppnullinitializedinitializedinitialized
permissionnot requestedgrantedgrantedgranted
fcmTokennullnullabc123abc123
messageStatusnonenonesentreceived
Key Moments - 3 Insights
Why do we need to request permission before getting the FCM token?
Because the token is only issued if the user allows notifications, as shown in execution_table step 2 and 3.
What happens if the user denies permission?
No token is received and setup stops, as shown in execution_table step 6.
Why do we initialize Firebase before requesting permission?
Firebase must be ready to handle messaging requests, as shown in execution_table step 1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result after requesting permission?
AMessage sent
BPermission granted
CToken received
DPermission denied
💡 Hint
Check step 2 in the execution_table for the permission request result.
At which step does the FCM token get received?
AStep 1
BStep 5
CStep 3
DStep 6
💡 Hint
Look at the 'Result' column in execution_table step 3.
If the user denies permission, what happens to the token variable?
AIt stays null
BIt becomes 'abc123'
CIt becomes 'permission denied'
DIt gets deleted
💡 Hint
Refer to variable_tracker for 'fcmToken' after step 2 and step 6.
Concept Snapshot
FCM setup steps:
1. Create Firebase project and enable Cloud Messaging.
2. Download config and add to app.
3. Initialize Firebase in app code.
4. Request user permission for notifications.
5. Get FCM token if permission granted.
6. Use token to send and receive messages.
Full Transcript
To set up Firebase Cloud Messaging (FCM), first create a Firebase project and enable Cloud Messaging. Download the configuration file and add it to your app. Initialize Firebase in your app code. Then request the user's permission to send notifications. If permission is granted, get the FCM token. Use this token to send messages to the device. The device can then receive and display messages. If permission is denied, no token is received and setup stops.