更新时间:2023-12-03 16:22:52
Firebase 云消息传递 (FCM) 主题消息传递允许您向已选择加入特定主题的多个设备发送消息.基于发布/订阅模型,主题消息支持每个应用程序的无限订阅,即您的组附加到特定主题,如新闻组、体育组等.
Firebase Cloud Messaging (FCM) topic messaging allows you to send a message to multiple devices that have opted in to a particular topic. Based on the publish/subscribe model, topic messaging supports unlimited subscriptions for each app i.e your group is attached to specific topic like news group,sports group etc.
FirebaseMessaging.getInstance().subscribeToTopic("news");
取消订阅unsubscribeFromTopic("news")
从服务器端,您需要设置特定主题,即一组用户,如下所示:
From Server side you need to set up for specif topic i.e a group of user like this:
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/news",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!",
}
}
"/topics/news"
这将向订阅新闻主题的人群发送通知
"/topics/news"
This will send notification to group of people who have subsribe the news topic