如何使用 Firebase Cloud Messaging 向所有设备发送通知 [英] How to send notifications to all devices using Firebase Cloud Messaging
问题描述
在 Firebase 文档中,它始终有一个带有设备/令牌 ID 的to"字段......但我怎样才能让它向所有设备发送通知.我用什么替换 to 字段,或者我在那里输入什么值.我已经完全删除了它,但它回来时出现了一个错误要求它.有什么想法吗?
On the Firebase doc, it always has a "to" field with a device/token id... but how can I get it to send the notification to all devices. What do I replace the to field with, or what value do I put in there. I'd removed it altogether but it comes back with an error asking for it. Any ideas?
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"data" : {
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
},
}
推荐答案
正如 Frank van Puffelen 所说,没有办法发送到所有设备.您可以使用以下方式在应用程序端为每个人订阅一个主题:
As Frank van Puffelen said there isn't a way to send to all devices. What you could do is to subscribe everyone to a single topic in the app side using:
FirebaseMessaging.getInstance().subscribeToTopic("TopicName");
所以你的信息应该是这样的:
So your message would look like this:
{
"to" : "/topics/TopicName",
"data" : {
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
},
}
主题是在 Firebase 服务器端自动创建的,但有时需要一段时间才能显示在 Firebase 下拉列表中.
The topic is automatically created in the Firebase server side, but sometimes it takes a while to show up in the Firebase drop down list.
单个主题的用户数不限.
The number of users in a single topic are unlimited.
这篇关于如何使用 Firebase Cloud Messaging 向所有设备发送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!