如何使用FCM定位登录用户? [英] How to target a logged user with FCM?

查看:55
本文介绍了如何使用FCM定位登录用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对推送通知特别是FCM(Firebase云消息传递)非常陌生.

I'm very new with push notifications and FCM (Firebase Cloud Messaging) in particular.

我有一个用户可以登录的应用程序,我想向该特定用户发送推送通知.用户可以同时在多个设备上登录,因此必须将通知发送到所有这些设备.

I have an app where the user can log in and I want to send push notification to this specific user. The user can be logged in on multiple devices at the same time so the notification must be sent to all this devices.

我知道如何通过我已经按照官方文档中的指南进行操作,并且我拥有一台用于注册用户的服务器.

I know how to send a notification to a specific device as I've followed the tutorial from the official documentation, and I have a server where the user is registered.

因此,我正在考虑将令牌( FirebaseInstanceId.getInstance().getToken())保存到我的服务器,然后向该用户下保存的所有令牌发送推送通知.

So I was thinking of saving the token (FirebaseInstanceId.getInstance().getToken()) to my server to then send a push notification to all the tokens saved under this user.

但是有两个问题:

  • 如果用户注销并且另一个用户登录,因为令牌相同,会发生什么?
  • 由于令牌可能过期或不再相关(用户已更改设备或删除了应用程序),我如何知道要在数据库中保留哪些令牌?

这就是为什么我认为我的方法可能是错误的,并且可能有更好的方法来做到这一点.

That's why I'm thinking that my approach is maybe wrong and there is probably a better way to do that.

我已经看到您可以直接在Firebase中管理用户,通过使用Firebase身份验证来对用户进行身份验证.所以我想知道这是否是我需要做的吗?

I've seen that you can manage users directly in Firebase, by authenticate your user using Firebase Authentication. So I'm wondering if this is what I need to do?

推荐答案

如果用户注销并且另一个用户登录,因为令牌相同,会发生什么?

正确处理注销.

由于令牌可能过期或不再相关(用户已更改设备或删除了应用程序),我如何知道哪些令牌保留在数据库中?

您可以从服务器端进行检查.

这篇关于如何使用FCM定位登录用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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