这是我需要使用 Firebase 将通知发送到特定设备时的 JSON 结构.那么我应该如何修改它以向所有设备或几个选定的设备发送相同的通知?
This is the JSON structure when I need to send the notification to specific device using Firebase. So how should I modify it to send the same notification to all of the devices or couple of selected devices?
{ "notification": {
"title": "Quiz App",
"text": "Your Quiz has submitted Successfully."
},
"to" : "Unique Key"
}
在 Android 中使用 Firebase 向所有设备发送推送通知的 JSON 结构是什么?
What will be the JSON structure for sending the push notification to all of the devices using Firebase in android?
如果您正在寻找一个有效负载参数来指定您打算将消息发送给所有用户,那么很遗憾,它不存在.
If you are looking for a payload parameter to specify that you intend the message for all your users, unfortunately, it doesn't exist.
通常,当向多个用户发送通知时,您可以使用 registration_ids
参数而不是 to
.但是,它最多只允许 1000 个注册令牌.如果您打算使用它,您可以发出 1000 个注册令牌的批量请求,遍历您存储在应用服务器中的所有注册令牌.
Commonly, when sending notifications to multiple users, you can make use of the registration_ids
parameter instead of to
. However, it only has a maximum of 1000 registration tokens allowed. If you intend to use this, you can make batch requests of 1000 registration tokens each, iterating over all the registration tokens you've stored in your app server.
正如@looptheloop88 已经提到的,您可以使用 Firebase 控制台向特定应用的所有用户发送消息,但如果您打算通过自己的应用服务器发送消息,最方便的方式是你可以做的是使用 Topic Messaging.根据@DiegoGiorgini 评论的可能重复帖子中的答案:
As already mentioned by @looptheloop88, you can make use of the Firebase Console to send a message to all the users of a specific app, but if you're planning to send it via your own App Server, the most convenient way you can do is make use of is Topic Messaging. As per the answer in the possible duplicate post I commented by @DiegoGiorgini:
只能通过 Web 控制台向所有手机发送消息,就像您在 Firebase Web 控制台中所做的那样.如果您需要 API 中的此功能,您可以提交功能请求:https://firebase.google.com/support/contact/bugs-features/
Sending a message to all the phones like what you do from the Firebase Web Console is only possible from the Web Console. If you need this feature from the API you can submit a feature request: https://firebase.google.com/support/contact/bugs-features/
另一种可能性是让所有客户端通过 FirebaseMessaging.getInstance().subscribeToTopic(topicName)
通过这种方式,您可以向整个主题发送消息,而无需手动收集registration-id.
但是,请记住,不支持对发送到主题的消息进行诊断.
这篇关于使用 Firebase 向所有已注册设备发送推送通知的 JSON 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!