JSON数据将推送通知发送到使用Firebase的所有注册设备 [英] JSON Data to send Push Notification to all of the registered devices using Firebase

查看:150
本文介绍了JSON数据将推送通知发送到使用Firebase的所有注册设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我需要使用Firebase将通知发送到特定设备时,这是JSON结构。那么我应该如何修改它以发送相同的通知给所有的设备或选定的设备?

  {notification :{
title:Quiz App,
text:您的测验已经成功提交。

to:Unique Key
}



<如何在Android中使用Firebase发送推送通知到JSON结构?

解决方案

正在寻找一个有效载荷参数,以指定你打算为所有的用户的消息,不幸的是,它不存在。



通常,当发送通知给多个用户时,您可以使用 registration_ids 参数,而不是。但是,最多只能有1000个注册令牌。如果你打算使用它,你可以批量请求1000个注册令牌,迭代你存储在你的应用服务器中的所有注册令牌。



您可以使用Firebase控制台向特定应用程序的所有用户发送消息,但是如果您计划通过自己的应用程序服务器发送消息,则可以使用最便捷的方法使用是主题信息。根据答案中可能的重复帖子我评论@DiegoGiorgini:


只有通过Web控制台才能将消息发送到所有手机,例如您从Firebase Web控制台执行的操作。如果您需要使用API​​中的此功能,您可以提交功能请求: https:// firebase.google.com/support/contact/bugs-features/



另外一种可能性是让所有的客户都通过一个特定的主题注册 FirebaseMessaging.getInstance()。subscribeToTopic(topicName)

发送一个消息到整个主题,而不手动收集注册ID。


但是请记住, a href =https://stackoverflow.com/a/39389049/4625829>不支持发送给主题的邮件的诊断功能。


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"
}

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.

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.

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:

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/

Another possibility is to have all the client registering to a specific topic via FirebaseMessaging.getInstance().subscribeToTopic(topicName)

In this way you can send a message to the whole topic without collecting the registration-ids manually.

However, do keep in mind that Diagnostics for messages sent to Topics are not supported.

这篇关于JSON数据将推送通知发送到使用Firebase的所有注册设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆