使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Firebase Cloud Messaging
plat_ios
plat_android
plat_web
plat_flutter
plat_cpp
plat_unity
Firebase Cloud Messaging (FCM) 是一种跨平台消息传递解决方案,可供您可靠地发送消息。
使用
FCM,您可以通知客户端应用有新的电子邮件或其他数据有待同步。您可以发送通知消息进行用户再互动并留住他们。在即时通讯等使用情形中,一条消息可将最多 4096 字节的载荷传送至客户端应用。
准备好开始了吗?选择您的平台:
iOS+
Android
Web
Flutter
Unity
C++
主要功能
发送通知消息或数据消息 |
发送向用户显示的通知消息。
或者发送数据消息,并完全在应用代码中决定具体的行动。请参阅消息类型。 |
通用消息定位 |
使用以下三种方式中的任意一种将消息分发到客户端应用:分发至单一设备、分发至设备组或分发至订阅了主题的设备。 |
工作原理
FCM 实现包括用于发送和接收的两个主要组件:
- 一个受信任的环境,例如 Cloud Functions for Firebase 或用于构建、定位和发送消息的应用服务器。
- 一个通过针对具体平台的相应传输服务接收消息的 Apple、Android 或 Web (JavaScript) 客户端应用。
您可以通过 Firebase Admin SDK 或 FCM 服务器协议发送消息。
您可以使用 Notifications Composer 进行测试,并使用强大的内置定位和分析功能或自定义导入的细分发送营销或互动消息。
如需详细了解 FCM 组件的相关重要信息,请参阅架构概览。
实现流程
|
设置 FCM SDK |
根据适用于您的平台的设置说明,在您的应用上设置 Firebase 和 FCM。 |
|
开发您的客户端应用 |
向您的客户端应用添加消息处理、主题订阅逻辑或其他可选功能。在开发过程中,您可以轻松地从 Notifications Composer 发送测试消息。 |
|
开发您的应用服务器 |
确定您要使用 Firebase Admin SDK 还是服务器协议来创建发送逻辑,这些逻辑将用于身份验证、构建发送请求、处理响应等等。然后,在您信任的环境中构建逻辑。 |
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-18。
[null,null,["最后更新时间 (UTC):2025-08-18。"],[],[],null,["Firebase Cloud Messaging \nplat_ios plat_android plat_web plat_flutter plat_cpp plat_unity \nFirebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send\nmessages. \nUsing FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4096 bytes to a client app.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nReady to get started? Choose your platform:\n\n[iOS+](/docs/cloud-messaging/ios/client)\n[Android](/docs/cloud-messaging/android/client)\n[Web](/docs/cloud-messaging/js/client)\n[Flutter](/docs/cloud-messaging/flutter/client)\n\n[Unity](/docs/cloud-messaging/unity/client)\n[C++](/docs/cloud-messaging/cpp/client)\n\nKey capabilities\n\n|---------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Send notification messages or data messages | Send notification messages that are displayed to your user. Or send data messages and determine completely what happens in your application code. See [Message types](/docs/cloud-messaging/concept-options#notifications_and_data_messages). |\n| Versatile message targeting | Distribute messages to your client app in any of 3 ways---to single devices, to groups of devices, or to devices subscribed to topics. |\n\nHow does it work?\n\n\u003cbr /\u003e\n\nAn FCM implementation includes two main components for\nsending and receiving:\n\n1. A trusted environment such as Cloud Functions for Firebase or an app server on which to build, target, and send messages.\n2. An Apple, Android, or web (JavaScript) client app that receives messages via the corresponding platform-specific transport service.\n\n\u003cbr /\u003e\n\nYou can send messages via\nthe [Firebase Admin SDK](/docs/cloud-messaging/server#firebase-admin-sdk-for-fcm) or the\n[FCM server protocol](/docs/cloud-messaging/server#choose).\nYou can use [the Notifications composer](//console.firebase.google.com/project/_/notification) for testing and to send marketing or engagement\nmessages using powerful built-in targeting and analytics or custom\n[imported segments](/docs/projects/import-segments).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nSee the [architectural\noverview](/docs/cloud-messaging/fcm-architecture) for more detail and important\ninformation about the components of FCM.\n\n\u003cbr /\u003e\n\nImplementation path\n\n|---|-------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | Set up the FCM SDK | Set up Firebase and FCM on your app according to the setup instructions for your platform. |\n| | Develop your client app | Add message handling, topic subscription logic, or other optional features to your client app. During the development, you can easily send test messages from [the Notifications composer](//console.firebase.google.com/project/_/notification). |\n| | Develop your app server | Decide whether you want to use the Firebase Admin SDK or the server protocol to create your sending logic---logic to authenticate, build send requests, handle responses, and so on. Then build out the logic in your trusted environment. |\n\nNext steps\n\n- Run the [Android](https://github.com/firebase/quickstart-android/tree/master/messaging)\n or [iOS](https://github.com/firebase/quickstart-ios/tree/master/messaging/)\n Quickstart sample. These samples let you run and review code to send a test\n message to a single device using the Firebase console.\n\n- Learn more about FCM from the\n [architecture overview](/docs/cloud-messaging/fcm-architecture),\n guides to key [FCM concepts](/docs/cloud-messaging/concept-options),\n and best practices guides for [sending messages at scale](/docs/cloud-messaging/scale-fcm)\n and [managing registration tokens](/docs/cloud-messaging/manage-tokens).\n\n- Try the tutorials for [Android](/docs/cloud-messaging/android/first-message)\n or [iOS](/docs/cloud-messaging/ios/first-message).\n\n- Add Firebase Cloud Messaging to your\n [Android](/docs/cloud-messaging/android/client),\n [Apple](/docs/cloud-messaging/ios/client),\n or [Web](/docs/cloud-messaging/js/client) app.\n\n- Set up your trusted environment where you'll build and send message requests.\n You can write sending logic using the\n [Admin SDK](/docs/cloud-messaging/server#firebase-admin-sdk-for-fcm), and\n readily deploy that code on Cloud Functions for Firebase or other cloud\n environments managed by Google.\n Alternatively, you can perform server development using the\n [FCM server protocol](/docs/cloud-messaging/server#choose)."]]