问题描述
我很困惑,我可以使用此令牌(存储在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将获取更新的令牌。
这些标记完全相同。