作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用这个众所周知的代码在我的服务器上保存一个新的 firebase token (来自:Retrieve the current registration token):
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// If you want to send messages to this application instance or
// manage this apps subscriptions on the server side, send the
// Instance ID token to your app server.
sendRegistrationToServer(refreshedToken);
}
问题是,如果用户在其他设备上安装该应用程序,将执行相同的代码,并且之前的 firebase token 将被新 token 覆盖。
所以我必须区分设备,但我该怎么做呢? Device name肯定不够独特。
编辑:不幸的是,Bob Snyder 的建议没有奏效。 FirebaseInstanceId#getId()如果我删除应用程序数据(缓存)或重新安装应用程序,总是不同的。
最佳答案
token 对于每台设备都是唯一的,并且包含应用程序实例 ID。 11 个字符的实例 ID,与 FirebaseInstanceId.getInstance().getId() 返回的相同, 首先出现,然后是冒号,然后是 token 的其余部分。示例:
eiURDSe_P4q:APA91bFvtCzK...LRpzvQOSdNKioklO
您可以使用实例 ID 作为唯一键来将 token 存储在服务器上。
关于android - 如果用户有多个设备,如何在我的服务器上存储 firebase token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43172532/
我是一名优秀的程序员,十分优秀!