Android用户注销时如何释放Firebase Cloud Messaging令牌? [英] How to release Firebase Cloud Messaging token when Android user logs out?

查看:57
本文介绍了Android用户注销时如何释放Firebase Cloud Messaging令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个涉及Firebase Cloud Messaging的Android应用.我的消息包含带有数据有效负载的通知,并通过node.js脚本发送到Firebase服务器.此设置与 Firebase博客,但一个区别是我不使用主题订阅,而是直接将消息发送给由Firebase InstanceID令牌标识的用户.我在Firebase数据库中为每个用户跟踪此令牌.

I'm developing an Android app that involves Firebase Cloud Messaging. My messages consist of notifications with data payload, and are sent to the Firebase server by means of a node.js script. This setup is very similar to what is explained in this Firebase blog, but one difference is that I do not make use of topic subscription, but rather send my messages directly to a user, identified by the Firebase InstanceID token. I keep track of this token for each user in my Firebase database.

此设置有效,但是当一个用户注销我的Android应用程序(例如,因为另一个用户想要使用同一设备登录)时,我必须防止收到刚刚注销的用户的通知.

This setup works, but when a user logs out my Android app (for example because another user wants to log on using the same device), I have to prevent receiving notifications for the user that just logged off.

我打算在用户登录时获取一个新令牌:

I was planning to get a new token when a user logs on:

FirebaseInstanceId.getInstance().getToken();

,并在该用户注销时释放它.但是,这就是我迷路的地方.在文档中,我找到了删除令牌的命令:

and release it when that user logs off. However, this is the point where I got lost. In the documentation, I found the command to delete the token:

public void deleteToken (String authorizedEntity, String scope)

但是我不知道字符串"authorizedEntity"和"scope"应该包含什么.有人可以通过删除令牌将我指向正确的方向,还是将我完全误入歧途(我几乎找不到任何相关的问题,这使我感到惊讶)?

but I can't figure out what the strings "authorizedEntity" and "scope" should contain. Can someone point me in the right direction, or am I on the wrong track altogether by deleting tokens (I could hardly find any related questions, which surprised me)?

推荐答案

Firebase实例ID令牌标识您的应用程序的已安装实例.试图改变其含义是头痛的秘诀.

The Firebase Instance ID token identifies an installed instance of your application. Trying to change its meaning is a recipe for headaches.

您不应使用它来识别用户.因此,除非用户卸载应用程序(在这种情况下,令牌会自动删除),否则用户注销后不应尝试删除令牌.

You should not use it to identify a user. So unless the user uninstalls the app (in which case the token is automatically deleted), you should not try to delete the token when the user logs out.

如果您希望在用户退出后停止向其发送通知,则应在数据库中进行跟踪:用户A正在使用令牌B".

If you want to stop sending notifications to a user-on-a-device once they sign out, you should track that in your database: "user A is using token B".

UserTokens
  UserA: "tokenB"

然后,您可以在用户注销时清除该数据:用户A不再使用令牌".

Then you can clear that data when the user signs out: "user A is no longer using a token".

UserTokens
  UserA: ""

然后,当用户B在同一设备上登录同一应用时,他们将获得相同的令牌:

Then when user B signs in to the same app on the same device, they'd get the same token:

UserTokens
  UserB: "tokenB"

这篇关于Android用户注销时如何释放Firebase Cloud Messaging令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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