如何为每个用户处理多个Firebase FCM令牌? [英] How to handle multiple Firebase FCM tokens per user?

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

问题描述

从官方文档中我了解到它的工作方式是这样的:

From the official documentation I understand that the way it works is something like this:

  1. 用户安装应用,生成FCM令牌
  2. 将令牌发送到应用服务器
  3. 服务器使用令牌将推送通知发送到此设备.

如果该用户同时在另一台设备上安装应用程序,该怎么办?我应该在每个用户的应用程序服务器上存储多个令牌吗?如果是,这意味着应该有类似检查哪些已过期的东西?

What if at the same time this user installs app on the other device - should I store multiple tokens per user on the app server? If yes - that means there should be something like checking for which ones are expired?

推荐答案

我也遇到了确切的挑战,不得不解决一个问题: 根据设备ID为用户存储每个令牌. 有趣的是,知道此功能实际上存在于firebase消息传递方法中.但是更令人惊讶的是,没有文档可以处理这种情况. https://firebase.google .com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId.html#getId()

I also came across the exact challenge and had to resolve to a solution: Storing each token for the user against the device id. It's interesting enough to know that this function in fact exists in the firebase messaging method. But more surprising is the fact that there's no documentation to handle such scenario. https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId.html#getId()

概括地说,在将新令牌发送到服务器时,还应随同getId()方法返回的设备ID一起发送,并使用它来强制每个设备使用令牌的唯一性.

Summarily, while sending the new token to the server, also send along the device id returned by the getId() method and use it to enforce uniqueness of token per device.

要在利用FCM的设备分组功能的同时应用此解决方案,您可以在FCM组上发出服务器请求,以便删除该设备ID上的旧令牌,然后将其替换为新令牌.

And to also apply this solution while taking advantage of device grouping feature of FCM, you can make a server request on the FCM group, in order to delete the old token on that device-id before replacing it with the new.

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

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