android - FCM 组还是 token 数组?

标签 android firebase push-notification firebase-cloud-messaging

我是 FCM 新手,我正在寻找如何将云消息传递添加到我的项目的最佳方法。

我需要向可以登录多个设备的用户发送通知。根据Firebase documentation ,有一些专门用于此目的的组:

Typically, "group" refers a set of different devices that belong to a single user.

但是根据this ,最新的 HTTP v1 API 不支持组。

我是否应该将组视为遗留组,而是将消息发送到用户所有存储的 token ?

最佳答案

HTTP 和 XMPP 协议(protocol)都支持组,正如您在发布的第一个链接中所看到的:

You can use device group messaging with the Admin SDKs, or by implementing the XMPP or HTTP protocols on your app server. The maximum number of members allowed for a notification key is 20.

因此,您没有理由将群组视为遗留。

Downstream XMPP messages 的文档中也说明了这一点:

Downstream XMPP messages (JSON)

to Optional, string

This parameter specifies the recipient of a message.

The value can be a device's registration token, a device group's notification key, or a single topic (prefixed with /topics/). To send to multiple topics, use the condition parameter.

编辑:

看到您的问题编辑后,您应该使用适合您要求的协议(protocol)。 FCM HTTP v1 是最新的 API 并不意味着您必须使用它,因为它不支持 旧版 HTTP 和 XMPP。

例如,如果您想使用上游消息传递,则不能使用 FCM HTTP v1:

You'll need to decide on a way to interact with FCM servers: either using the Admin SDK or the raw protocols. Among the raw protocol options, the FCM HTTP v1 API is the most up to date, with more secure authorization and flexible cross-platform messaging capabilities. The legacy HTTP and XMPP server protocols area also available. Note that if you want to use upstream messaging from your client applications, you must use XMPP.

同样,如果您决定使用 HTTP v1 API,则必须将消息发送到给定用户的各个 token 。

关于android - FCM 组还是 token 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48763311/

相关文章:

java - 按下主页按钮后如何在Android中播放mediaPlayer并在收到电话时恢复播放视频?

ruby-on-rails - 如何在 ruby​​ 中重试 rpush 通知?

android - 无法在应用程序处于后台时收到 "open"通知

android - Admob 广告和 Firebase 广告之间的区别

Typescript Firebase 定义文件,Promises

angular - typescript : error TS2740: Type '{}' is missing the following properties from type 'Product[]' : length, 弹出、推送、连接等 26 个

android - 在 Android Studio 中通过 firebase 发送通知的 Gradle 设置问题

android - 将 MotionEvent.getX() 与 Android 中的屏幕宽度进行比较

android - RxJava2- Completable永无止境

android - 在Google Play应用程序中用特殊字符搜索