Firebase - 在不知道其成员的注册ID的情况下删除设备组 [英] Firebase - Delete a device group without knowing the registration ids of its members

查看:751
本文介绍了Firebase - 在不知道其成员的注册ID的情况下删除设备组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Firebase和设备组时,我正在测试令牌(注册ID)发生变化的情况(例如重新安装应用程序之后),但由于重新安装应用程序后,我的逻辑失败,因此无法了解先前存储的令牌。
$ b $问题是现在我有一个设备组有两个ghost注册ID,我不知道了,因为他们改变了。

我知道在每个成员都被注销之后,组会被删除,但是我不知道注册ID是否需要手动注销。



我能做什么?

是否有办法检索设备组的成员或删除它一次?

另外,什么是一个好的方法来管理的情况下,令牌刷新?

解决方案


我知道每个成员都被注销后,组被删除,但我不知道注册ID手动取消注册。我能做什么?


当您向设备组发送消息时,您会收到一个响应,其中包含一个成功失败参数。 0 失败的值意味着我们正在FCM服务器中排队的消息。



失败的消息,失败的注册令牌列表将在响应中,其中建议重试发送消息。请参阅文档


$ b


发送下游消息到设备组

发送消息到设备组与将消息发送到单个设备非常相似。将参数设置为设备组的唯一通知密钥。有关负载支持的详细信息,请参见消息类型。这个页面中的例子展示了如何使用HTTP和XMPP协议向设备组发送数据消息。
$ b

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

{
to:aUniqueKey,
data:{
hello:这是一个Firebase Cloud Messaging Device Group Message!,
}
}

HTTP响应



以下是成功的示例 - notification_key 有2个注册记号消息被成功发送给他们两个:

  {
success:2,
failure:0
}

下面是一个部分成功 - notification_key 有3个与其相关的注册标记。该消息仅被成功发送到注册令牌中的一个。响应消息列出了未能收到消息的注册令牌:

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

当一条消息传递给一个或多个与 notification_key

然而,在您执行重试之前,您可以首先执行重试操作,验证FCM令牌是否仍然有效(通过使用 dry_run 或实例ID服务器API)。如果显示设备不再有效(通常 NotRegistered ,您应该从设备组和应用程序服务器中删除该令牌(或将其移至垃圾日志或其他内容)。


另外,管理令牌刷新情况的好方法是什么? b

如果令牌被刷新(通过 onTokenRefresh()),要做的事情是找到旧令牌用户拥有并替换它与新的一个,适用于重要的变化(这也是映射设备组)。



另请参阅我的答案此处此处。细节可能会有所帮助。


While working with Firebase and Device Groups, I was testing the case in which the token (registration id) changes (for example after reinstalling the app) but my logic failed because after reinstalling the app i have no more way to know the previously stored token .

The problem is that now I have a device group with two "ghost" registration ids that I don't know anymore because they changed.

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?

Is there a way to retrieve the members of a device group or deleting it at once?

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

解决方案

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?

When you send a message to a device group, you'll receive a response that contains a success and failure parameters. 0 value for `failure means that the messages we're queued properly in the FCM servers.

It there were failed messages, the list of registration tokens that failed will be in the response, where the advise is to retry sending the message. Referring to the 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.

However, before you perform a retry, you could first verify if the FCM token is still valid (either by using dry_run or the Instance ID Server API). If it shows that the device is no longer valid (usually NotRegistered, you should then remove that token from the device group and from your App Server (or move it to a trash logs or something).

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

If the token gets refreshed (through onTokenRefresh()), the thing to do is to find the old token the user has and replace it with the new one, applying the changes where it matters (which is also mapping the device groups).

Also see my answers here and here. Some details might be helpful.

这篇关于Firebase - 在不知道其成员的注册ID的情况下删除设备组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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