IndexedDB firebase-messaging-store中此“令牌”的含义是什么

问题描述

IndexedDb Token for firebase cloud messaging


我很困惑,我可以使用此令牌(存储在indexedDb中)来为设备订阅主题或向设备发送推送通知吗? 这个令牌的意义是什么?


最好的问候

谢谢

解决方法

该数据库很可能是Firebase Cloud Messaging客户端存储设备令牌的方式。但是,这没有记录,因此您不应该依赖此数据库条目。

相反,如果要使用令牌(订阅主题或其他原因),请使用public API to get the token

messaging.getToken().then((currentToken) => {
  ...
});

上面的可以从indexeddb中读取令牌,但是它也可以从对FCM服务器的调用中主动获取令牌。

,

正如弗兰克所说,

const localStorageKey = 'webpush';
messaging.getToken().then((currentToken) => {
if (localStorage.getItem(localStorageKey) !== currentToken) {
   localStorage.setItem(localStorageKey,currentToken); 
}
...
});

Firebase将令牌存储在索引数据库中。刷新令牌时,IndexedDb将获取更新的令牌。


IndexedDb


LocalStorage

这些标记完全相同。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...