gpt4 book ai didi

android - Firebase - 在不知道其成员的注册 ID 的情况下删除设备组

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:49:14 25 4
gpt4 key购买 nike

在使用 Firebase 和设备组时,我正在测试 token (注册 ID)发生变化的情况(例如在重新安装应用程序之后),但我的逻辑失败了,因为在重新安装应用程序之后我无法知道先前存储的 token 。

问题是,现在我有一个设备组,其中有两个我不再知道的 "ghost" 注册 ID,因为它们已更改。

我知道在每个成员注销后该组将被删除,但我不知道注册 ID 以手动注销它们。

我能做什么?

有没有办法检索设备组的成员或立即删除它?

此外,管理 token 刷新情况的好方法是什么?

最佳答案

I know the group get removed after every member has been unregistered but I don't know the registration ids to unregister them manually. What can I do?

当您向设备组发送消息时,您将收到包含成功失败 参数的响应。 `failure 的 0 值表示我们在 FCM 服务器中正确排队的消息。

如果有失败的消息,失败的注册 token 列表将在响应中,建议重试发送消息。引用docs :

Sending downstream messages to device groups

Sending messages to a device group is very similar to sending messages to an individual device. Set the to parameter to the unique notification key for the device group. See Message types for details on payload support. Examples in this page show how to send data messages to device groups in HTTP and XMPP protocols.

HTTP POST Request

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{
"to": "aUniqueKey",
"data": {
"hello": "This is a Firebase Cloud Messaging Device Group Message!",
}
}

HTTP Response

Here is an example of "success"— the notification_key has 2 registration tokens associated with it, and the message was successfully sent to both of them:

{
"success": 2,
"failure": 0
}

Here is an example of "partial success" — the notification_key has 3 registration tokens associated with it. The message was successfully sent to 1 of the registration tokens only. The response message lists the registration tokens that failed to receive the message:

{
"success":1,
"failure":2,
"failed_registration_ids":[
"regId1",
"regId2"
]
}

When a message fails to be delivered to one or more of the registration tokens associated with a notification_key, the app server should retry with backoff between retries.

但是,在执行重试之前,您可以先 verify if the FCM token is still valid (通过使用 dry_run 或 Instance ID Server API)。如果它显示该设备不再有效(通常为 NotRegistered ,您应该从设备组和您的应用服务器中删除该 token (或将其移至垃圾日志或其他内容)。

Also, what is a good way to manage the case in which the token gets refreshed?

如果 token 被刷新(通过 onTokenRefresh()),要做的事情是找到用户拥有的旧 token 并将其替换为新 token ,在重要的地方应用更改(这也在映射设备组)。

另见我的回答 herehere .一些详细信息可能会有所帮助。

关于android - Firebase - 在不知道其成员的注册 ID 的情况下删除设备组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43503813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com