这是关于Stack Overflow的第一个问题!
我正在尝试使用'在firebase服务器上部署我的firebase应用程序。 firebase部署'命令。在运行"消息传递"示例[由Firebase提供]在我的本地计算机上,生成实例ID没有问题。但是,当我在Firebase服务器上部署应用程序并在浏览器中运行应用程序时,应用程序无法从FCM服务器检索实例ID。这是我从Chrome控制台获得的响应片段:
No Instance ID token available. Request permission to generate one.
(index):226 Requesting permission...
(index):239 Unable to get permission to notify. V
(index):226 Requesting permission...
(index):239 Unable to get permission to notify. V {code:
"messaging/permission-blocked",
message: "Messaging: The required permissions were not grant… blocked instead. (messaging/permission-blocked)."}
code: "messaging/permission-blocked"message: "Messaging: The required permissions were not granted and blocked instead. (messaging/permission-blocked)."stack: (...) ....
答案 0 :(得分:3)
看起来你没有request permission to receive notifications:
方法
messaging.requestPermission()
会显示一个同意对话框,允许用户授予您的应用在浏览器中接收通知的权限。如果权限被拒绝,则FCM注册令牌请求会导致错误。messaging.requestPermission() .then(function() { console.log('Notification permission granted.'); // TODO(developer): Retrieve a Instance ID token for use with FCM. // ... }) .catch(function(err) { console.log('Unable to get permission to notify. ', err); });