Firebase云消息传递无法检索实例ID

3

这是我在Stack Overflow上的第一个问题!

我正在尝试使用“firebase deploy”命令将我的Firebase应用程序部署到Firebase服务器上。在我的本地计算机上运行Firebase提供的“messaging”示例时,生成实例ID没有任何问题。然而,当我将应用程序部署到Firebase服务器并在浏览器中运行应用程序时,应用程序无法从FCM服务器检索Instance 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: (...) ....
1个回答

5

看起来您还没有请求接收通知的权限

The method messaging.requestPermission() displays a consent dialog to let users grant your app permission to receive notifications in the browser. If permission is denied, FCM registration token requests result in an error.

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);
});

我也看不到对话框。 - xtrinch
如果对话框没有显示,请尝试最小化和最大化Chrome窗口。之后对话框会显示出来。 - user1185087

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接