FCM (Firebase Cloud Messaging) is a cross-platform service from Google for delivering push notifications and transferring data between a server and mobile applications. It supports Android, iOS, and web platforms through a single API. According to Firebase Documentation, FCM processes over 1 billion messages daily worldwide.
Key Takeaways
Firebase Cloud Messaging (FCM) is a cloud service from Google that ensures reliable delivery of push notifications and data messages to mobile devices. Formerly known as Google Cloud Messaging (GCM), FCM has become the primary tool for cross-platform notifications in the Firebase ecosystem.
FCM automatically selects the optimal delivery channel depending on the platform: on Android, it uses its own FCM connection; on iOS, it uses APNS (through the FCM gateway). The developer does not need to implement two different integrations — FCM handles the routing.
The service provides a unified REST API and Admin SDK for sending messages. This allows sending notifications from the server side without being tied to a specific recipient platform.
FCM supports several delivery modes: a single message to a specific device, group broadcast by topic, and segmented sending by conditions. Scheduled sending and A/B testing of notification content are also available.
The FCM architecture is based on three components: the client application, the Firebase Connection Server, and the app server. The client registers with FCM at startup and receives a unique registration token — a string that identifies the device for the given application.
The app server sends a request to the FCM REST API, specifying the recipient token or topic. The Firebase Connection Server delivers the message using a persistent XMPP connection or HTTP request. If the device is offline, the message is queued and delivered when the connection is restored.
FCM guarantees delivery using priority queues and an acknowledgment mechanism. On Android, the message is stored for up to 28 days in the queue; on iOS, up to 4 weeks (via APNS). After the expiration date, the message is deleted without notification.
The registration token can change in several cases: when restoring app data, when updating to a new version, or when clearing the cache. The app must implement FirebaseMessagingService.onNewToken to handle token updates and synchronize with the server.
FCM supports two types of payload: notification and data. Each type determines how and when the message is processed on the recipient device.
| Parameter | Notification | Data |
|---|---|---|
| Automatic display | Yes, if the app is in background | No, only in the app |
| Handling | System/NOS — in background; app — in foreground | Always in the app (onMessageReceived) |
| Maximum size | 4 KB | 4 KB |
| Custom keys | Limited to predefined fields | Any key-value pairs |
| Requires CollapseKey | Optional | Optional for grouping |
In practice, it is recommended to use data messages when the app needs full notification processing in onMessageReceived. Notification messages are suitable for simple scenarios where system display is sufficient.
FCM and APNS are the two main push delivery services. FCM works as a cross-platform gateway, while APNS is only for the Apple ecosystem. Their key differences lie in architecture, certificate requirements, and routing mechanisms.
The choice between FCM and direct APNS depends on the project architecture. For cross-platform applications, FCM is the optimal choice. For iOS-only projects, direct work with APNS via the HTTP/2 API is acceptable.
FCM is justified when the project uses both Android and iOS simultaneously, as well as when Firebase analytics, A/B testing of notifications, or topics without server logic are needed. Direct APNS is preferable for iOS-only applications with minimal dependencies and strict delivery latency requirements.
To connect FCM to an Android application, you need to add the Firebase SDK and configure google-services.json in the project root. After token registration, the application is ready to receive messages through FirebaseMessagingService.
// build.gradle (Module)
dependencies {
implementation("com.google.firebase:firebase-messaging:24.1.0")
}
// AndroidManifest.xml
<service android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
class MyFirebaseMessagingService :
FirebaseMessagingService() {
override fun onNewToken(token: String) {
sendTokenToServer(token)
}
override fun onMessageReceived(message: RemoteMessage) {
message.notification?.let {
showNotification(it.title, it.body)
}
}
}
After setup, the application automatically receives an FCM token on first launch. The token must be sent to the app server for subsequent notification delivery to this device.
On Android 8+, before sending an FCM notification with automatic display, you must create a NotificationChannel. FCM notification messages use the default channel ID, but it is recommended to create a custom channel through FirebaseMessagingService when receiving the first message. Data messages do not require a channel — the app decides itself how and when to show the notification.
On iOS, FCM acts as an intermediary between the app server and APNS. Firebase receives the message from the server, wraps it in APNS format, and sends it through the Apple gateway. The developer needs to configure an APNS key or certificate in the Firebase console.
import FirebaseMessaging
import UserNotifications
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions options: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
UNUserNotificationCenter.current().delegate = self
Messaging.messaging().delegate = self
return true
}
}
extension AppDelegate: MessagingDelegate {
func messaging(
_ messaging: Messaging,
didReceiveRegistrationToken fcmToken: String?
) {
UserDefaults.standard.set(fcmToken, forKey: "fcm_token")
}
}
On iOS, APNS registration happens asynchronously. The FCM SDK automatically obtains the APNS token and passes it to the Firebase server. didReceiveRegistrationToken fires when a new FCM token is received, which combines the APNS token with the project identifier.
FCM provides a Firebase console for monitoring delivery: the number of sent, received, and displayed notifications. A status callback is also available via Firebase Cloud Functions for tracking delivery errors on the server side. Key metrics: impressions and opens of notifications.
When working with FCM, it is important to choose the right message type for each scenario. For simple notifications with automatic display, use notification messages. For cases when the app needs to process data before displaying, use data messages. A mixed type (notification + data) is recommended only if the data is needed for analytics rather than changing the notification content.
Manage tokens centrally. Store current tokens on the server in a table linked to the user and platform. Implement a stale token cleanup mechanism: when encountering a NotRegistered or InvalidRegistration error, delete the token from the database. Tokens rarely change, but cleaning them is a mandatory element of FCM support.
Use collapse keys (collapseKey) for grouping messages. If you are sending multiple notifications of the same type (e.g., "currency rate update"), set the same collapseKey. FCM will deliver only the last message from the group, reducing device load and avoiding notification overload for the user.
Monitor delivery through Firebase Console and Cloud Functions. FCM analytics shows the number of sent, received, and displayed notifications. If the display rate is below 70%, check channel settings on Android and permission settings on iOS. Low delivery is often related to disabled channels or notification bans. Fifth: use Firebase A/B testing to optimize notification text and sending time — this increases open conversion by 15–25% according to Firebase data.
Frequently Asked Questions
FCM is the evolutionary update of GCM (Google Cloud Messaging). FCM offers simplified setup through the Firebase Console, built-in analytics, topics, and Web Push support. GCM was officially discontinued in April 2019, and all projects must be migrated to FCM.
Firebase Cloud Messaging is a free service with no limits on the number of messages. Payment is charged only for using other Firebase services such as Cloud Functions or Firestore. FCM does not require a Spark or Blaze subscription for basic notification delivery.
The FCM token changes when: restoring the application from backup, clearing app data, reinstalling, updating to a new version with a changed Sender ID. Always handle onNewToken in FirebaseMessagingService to send the new token to the server.
Google FCM is blocked in China. Alternative services are used for notification delivery in China: Huawei Push Kit, MiPush (Xiaomi), Oppo Push, Vivo Push. For cross-platform delivery, multi-provider services like Getui are used.
Use the built-in Firebase console: select "Cloud Messaging" — "Send Test Message". Enter a test token and send a notification message. The notification should appear on the device. You can also monitor FirebaseMessagingService.onMessageReceived logs.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also