Firebase Cloud Messaging - 向所有用户发送消息

Firebase Cloud Messaging - Send message to all users

我是 Firebase 云消息的新用户。我构建了一个 IOS 应用程序来接收推送通知。该应用程序运行良好。我从 Firebase 控制台发送消息,它们显示正确。

现在我正在尝试构建一个网络 api 以允许我的客户发送推送消息(无需访问 firebase 控制台)。研究文档 here 我意识到我总是有一个 "to",意思是组、主题或设备 ID。

我的问题是:我可以向所有设备发送消息(就像我可以在控制台中那样)吗?我是,怎么会?

提前致谢!

你可以利用话题。鉴于您的所有用户都订阅了一个特定的用户。就像我提到的(删除了一些部分,如果你想看的话):

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.

However, do keep in mind that .

我找到了 this:

!('TopicA' in topics)

With this expression, any app instances that are not subscribed to TopicA, including app instances that are not subscribed to any topic, receive the message.

所以你可能会使用

condition="!('nonExistingTopic' in topics)"