处理FCM设备组的刷新令牌 [英] Handling refresh tokens for FCM device groups

查看:227
本文介绍了处理FCM设备组的刷新令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过Node.js服务器在我的Android应用程序中实现Firebase云消息传递,并且遇到了一个用例。我看到了Firebase教程创建一个设备组使用注册令牌发送消息/通知到所有设备用相同的用户登录,我不明白的是当一个注册令牌被onTokenRefresh()方法刷新时会发生什么。





$ p

>更新:



好的,现在我已经陷入另一个阻塞用例了。我正在从我的服务器创建用户组标识的用户组。如果用户立即卸载并重新安装应用程序,并且其他用户在设备上登录,如果我在前一个用户组上调用gcm消息,该设备仍然会收到它。



有没有什么办法可以让gcm识别出它发送通知的设备是否被登录,如果是,是用同一个用户登录的吗?

onRefreshToken()被调用:


这不会被频繁调用对于密钥轮播和处理由于以下原因而导致的实例ID更改:
$ b $ ul

  • 应用程序删除实例ID
  • 应用程序
  • 用户卸载/重新安装应用程序
  • 用户清除应用程序数据

  • 猜测一下,你可以说'onTokenRefresh()`会在上述情况发生后调用,如果设备在线(当然,为了得到一个新的令牌,它必须在线))。所以我想这里是我怎么去的情景:

    首先,注册后,我会保存注册令牌,并沿着另一个标识符,让我们说一个在我的应用程序服务器中,deviceId(因为我们处于一个有多个设备的用户的情况)。

    因此假设我添加了3个注册令牌,那些也与他们的deviceIds配对。我将它们全部添加到设备组中。



    现在说其中一个设备触发 onTokenRefresh(),I会立即向我的应用程序服务器发送删除请求,以获取当前与该设备ID配对的注册令牌(您也应该在与其连接的任何设备组中将其删除),将其替换为新设备,然后重新添加它到相应的设备组。



    这是我能想到的最简单的方法。这里的关键是您将注册令牌与另一个标识符配对,并使用它来查找您需要替换的注册令牌。

    I am trying to implement Firebase cloud messaging in my Android app through a Node.js server and I have got stuck at a usecase.

    I saw the Firebase tutorial of creating a device group using registration tokens to send messages/notifications to all devices with the same user logged in, what I don't understand is what happens when one of the registration tokens get refreshed by onTokenRefresh() method.

    How will I distinguish which token to change as all will be belonging to the same user?

    Update:

    Ok, so now I have got stucked on another blocking use case. I am creating a user group identified by the user id from my server. If user uninstalls and reinstalls the app immediately and another user logs in on the device, if I call a gcm message on the previous user group this device still receives it.

    Is there any way for the gcm to identify is the device it is sending the notification to is logged in or not and if it is, is it logged in with the same user as for the group?

    解决方案

    So I've been thinking about how to go with this scenario. First off, let's put in the instances when onRefreshToken() is called:

    This will not be called very frequently, it is needed for key rotation and to handle Instance ID changes due to:

    • App deletes Instance ID
    • App is restored on a new device
    • User uninstalls/reinstall the app
    • User clears app data

    Guess with that, you can say that 'onTokenRefresh()` will be called after one the above happens and if the device is online (of course it has to be online on order to get a new token). So I guess here's how I'd go on the scenario:

    First off, upon registration, I would save the registration token and pair it along another identifier, let's say a deviceId (since we're in a scenario for a user with multiple devices) in my App Server.

    So assume I add in 3 registration tokens, those are also paired with their deviceIds. I add them all to a device group.

    Now say one of the devices triggers the onTokenRefresh(), I would immediately send a delete request to my App Server for the registration token that is currently paired to that deviceId (you should also delete it in any device group(s) it's connected to), replacing it with the new one, then re-add it to the corresponding device group(s).

    That's the simplest way I can think of. The key here is for you to pair the registration tokens with another identifier and use it to find which registration token you need to replace.

    这篇关于处理FCM设备组的刷新令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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