Learn how to set up Firebase Cloud Messaging (FCM) for Android and iOS with our step-by-step guide covering project creation, app integration, and server setup.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Create a Firebase Project
Step 2: Add Firebase to Your App
google-services.json file and place it in the app directory of your project.build.gradle file contains the Maven repository for Google:google-services plugin in your app-level build.gradle:build.gradle file:Register your app by entering the iOS bundle ID.
Download the GoogleService-Info.plist file and add it to your Xcode project.
Use CocoaPods to install Firebase in your project:
```
pod 'Firebase/Messaging'
```
Initialize Firebase in your App Delegate:
```swift
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
return true
}
}
```
Step 3: Set Up FCM Server Environment
Navigate to the Firebase Console, and go to the "Project Settings."
Click on the "Cloud Messaging" tab.
There, you will find the server key, which is necessary for sending messages.
For server-side setup, you can use any language or platform that can make HTTP POST requests. Below is an example using Node.js:
```javascript
const fetch = require('node-fetch');
async function sendMessage() {
const response = await fetch('https://fcm.googleapis.com/fcm/send', {
method: 'POST',
headers: {
'Authorization': 'key=YOUR_SERVER_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
to: 'DEVICE_REGISTRATION_TOKEN',
notification: {
title: 'Hello!',
body: 'This is a notification message.'
}
})
});
const data = await response.json();
console.log(data);
}
sendMessage();
```
Step 4: Implement FCM in Your App
FirebaseMessagingService:UNUserNotificationCenterDelegate to handle incoming notifications:Now, your app is set up to receive messages from Firebase Cloud Messaging. You can test sending notifications from the Firebase Console to confirm everything is working correctly.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.