Firebase Cloud Messaging:如何向所有用户发送数据消息? [英] Firebase Cloud Messaging: how to send data message to all users?

查看:203
本文介绍了Firebase Cloud Messaging:如何向所有用户发送数据消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向所有用户发送数据消息.

是否可以通过编程方式而不使用 Firebase Notifications Console ?

Is it possible to do it programmatically, without using the Firebase Notifications Console?

控制台的问题是表格开头的消息文本"字段是强制性的.因此,即使我添加了自定义数据键/值,也将有标准的通知组件.

The problem with the Console is that the "message text" field at the beginning of the form is compulsory. So, even if I add the custom data key/values, there will also be the standard notification component.

此处所述,当邮件中同时包含两个通知和数据,以防应用程序在后台运行,系统会在系统任务栏上通知标准的通知消息.

As stated here, when the message includes both notification and data, in case the app is in the background, a standard notification message will be notified to the system tray.

我想只发送基于自定义数据的通知(由OnMessageReceived触发).

I would like instead to deliver only a notification based on the custom data (trigged by OnMessageReceived).

我该如何实现?通过编程,我可以正确地将数据消息发送给特定用户,但是我找不到找到将数据消息发送给所有用户的方法.

How can I achieve that? Programmatically, I can correctly send data messages to specific users, but I cannot find a way to send data messages to ALL users.

推荐答案

使用主题消息.您可以定义应用程序的所有安装都将订阅的主题的名称,然后将消息发送到该主题.

Use topic messaging. You can define the name of a topic that all installations of your app will subscribe to, then send the message to that topic.

您可以使用服务器上的 Firebase管理SDK 发送该消息.或者,您可以使用 FCM HTTP API 发送该消息.

You can use the Firebase Admin SDK from your server to send that message. Or you can use the FCM HTTP API to send that message.

这篇关于Firebase Cloud Messaging:如何向所有用户发送数据消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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