何时为用户注册FCM令牌 [英] When to register an FCM token for a user

查看:95
本文介绍了何时为用户注册FCM令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于在我的应用程序中实施Firebase Cloud Messaging,我有些疑问.

I have some doubts about implementing Firebase Cloud Messaging in my app.

我的应用是类似于 whatsapp facebook Messenger 的聊天.现在,每次有人登录时,我都会注册令牌并将其与用户相关联.因此,如果有人想与用户聊天,则该应用会在Db中搜索用户ID,然后我就有他的令牌.

My app is a chat similar to whatsapp and facebook messenger. Right now every time someone logs in I register the token and relate it to the user. So if someone wants to chat to an user the app searches the Db for the user ID and there I have his token.

我能够注册设备令牌,但不确定何时应该这样做.

I'm able to register the device token but I'm not sure when should I do that.

在我的聊天中,用户通过邮件/密码注册进行注册,并且有可能用户可以登录其他设备.

In my chat users register through a mail/password signup and is possible that an user could login in other device.

例如: 用户Frehley使用 Galaxy 8 ,并能够使用令牌在其设备上聊天并接收通知.但是可以说他登录了另一台设备.我需要再次注册令牌并将其与他联系对吗?

For example: User Frehley uses a Galaxy 8 and is able to chat and receive notifications in his device using the token. But lets say that he loges in another device. I need to register the token again and relate it to him right?

所以,也许我错了,但是注册令牌的最佳时机是每次用户登录并将其替换到数据库中时.对吧?

So, maybe I'm wrong but the best moment to register the token is every time the user logs in and replace it in the DB. Right?

现在,假设有两个用户(Frehley和Stanley)使用相同的 Galaxy 8 登录,每次登录时令牌是不同的还是每个设备都相同?

Now, lets say two users (Frehley and Stanley) uses the same Galaxy 8 to login, the token will be diferent everytime the login or it is the same for every single device?

推荐答案

这全部取决于用例:

使用设备组消息传递,您可以将一条消息发送到在属于该组的设备上运行的应用程序的多个实例.通常,组"是指一组属于单个用户的不同设备

With device group messaging, you can send a single message to multiple instances of an app running on devices belonging to a group. Typically, "group" refers a set of different devices that belong to a single user

  • 如果希望用户仅在他们上次使用的设备上收到通知,则必须将单个令牌与每个用户相关联,并在他们在设备上启动应用程序时将其覆盖.并不是说他们登录时不一定如此,而是当应用程序检测到他们已通过身份验证.

    如果其他用户在同一设备上使用同一应用程序(使用相同的设备配置文件),则您可能想停止发送到设备令牌.执行此操作的最可靠的方法是删除以前的用户与令牌之间的关联,但是这可能需要您保留从令牌到UID的映射.一种更简单的方法是删除设备令牌用户注销时.然后,新用户登录,他们将获得一个新令牌.

    If a different user uses the same app on the same device (using the same device profile), you probably want to stop sending to the device token. The most robust way to do this is to remove the association between the previous user and the token, but that may require that you keep a mapping from token to UID. An easier way is to delete the device token when a user signs out. Then the new user signs in, they will then get a new token.

    这篇关于何时为用户注册FCM令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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