我正在关注 example在文件上,但我对注册 token 感到困惑。我正在本地 Express 服务器上测试推送通知。如何准确检索当前注册 token ,以及如何为多个网络应用程序用户生成注册 token ?
最佳答案
在文档中说:
// This registration token comes from the client FCM SDKs. var registrationToken = 'YOUR_REGISTRATION_TOKEN';`
获取用户的 token :
messaging.getToken().then(function(currentToken) {
if (currentToken) {
sendTokenToServer(currentToken);
updateUIForPushEnabled(currentToken);
} else {
// Show permission request.
console.log('No Instance ID token available. Request permission to generate one.');
// Show permission UI.
updateUIForPushPermissionRequired();
setTokenSentToServer(false);
}
}).catch(function(err) {
console.log('An error occurred while retrieving token. ', err);
showToken('Error retrieving Instance ID token. ', err);
setTokenSentToServer(false);
});
}
更多信息 here
然后将 token 添加到数据库并在 Admin SDK 中检索它
更多信息在这里:Retrieve data in Admin SDK
关于javascript - FCM Admin - 网络应用程序用户的注册 token 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49892389/