每个用户帐户的唯一Firebase实例ID [英] Unique Firebase Instance-Id for every user account

查看:61
本文介绍了每个用户帐户的唯一Firebase实例ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定如何在同一台设备上适当地处理不同的用户帐户,因为Firebase每个设备仅创建一个Instance-Id.

I'm unsure how to handle different user accounts on the same device appropriately, as Firebase only creates one Instance-Id per device.

因此,尽管如此,我可以在用户注销时删除Instance-Id,并在新用户登录时创建一个新实例.

Therefore, I though that it would be possible to delete the Instance-Id when the user is logged out and to create a new one when a new user is logged in.

登录时:

FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(task -> System.out.println(task.getResult().getToken()));

注销时:

FirebaseInstanceId.getInstance().deleteInstanceId()

Firebase是否可以确保实例ID将是唯一的,即使它在同一设备上多次生成?我之所以喜欢这种方法,是因为很容易一次将用户从所有主题中退订,而且可以将推送通知发送给特定用户.

Does Firebase ensure that the Instance-Id will be unique, even if it is generated multiple times on the same device? The reasons why I prefer this approach are that it's simple to unsubscribe the user from all topics at once and moreover push notifications can be addressed to a specific user.

推荐答案

Firebase是否可以确保实例ID是唯一的,即使它在同一设备上多次生成?

Does Firebase ensure that the Instance-Id will be unique, even if it is generated multiple times on the same device?

重新生成实例ID的确会产生唯一的值.只要确保您在用户注销时删除实例ID,下次您就会获得一个新的令牌.

Regenerating an Instance ID will indeed always result in a unique value. As long as you ensure that you delete the Instance ID when the user logs out, you'll get a fresh token next time around.

为确保令牌注册中心(存储令牌的地方)不会累积太多过时的令牌,请确保在用户注销时删除令牌,或者当发现令牌不再有效时,请删除令牌.发送消息.请参阅我对这个问题的回答.

To ensure your token registry (the place where you store tokens) doesn't accumulate too many outdated tokens, be sure to either remove the token when the user signs out, or when you find out a token is no longer valid when sending messages. See my answer to this question.

这篇关于每个用户帐户的唯一Firebase实例ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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