【问题标题】:Is the push notification feature in the firebase not supported by node.js?node.js 不支持 firebase 中的推送通知功能吗?
【发布时间】:2019-11-07 01:10:00
【问题描述】:

我目前正在开发 Nuxt.js + firebase 项目。 在“npm run dev”之后,我成功地从控制台窗口从设备获取了一个令牌。但是,当我在“npm run build”之后尝试“npm run start”时,我在控制台窗口中看不到设备的令牌。

根据 Google 的页面,node.js 不支持云消息传递功能。那么,Nuxt.js 不能在 firebase 上写推送通知功能吗?

https://firebase.google.com/docs/web/setup#namespace

【问题讨论】:

  • 一般来说,如果您包含minimal code that reproduces the problem,会更容易提供帮助。我不明白你想要完成什么。您是否尝试向 node.js 脚本发送推送通知?或者您是否尝试 node.js 脚本发送推送通知?

标签: firebase google-cloud-functions nuxt.js


【解决方案1】:

使用npm run dev 运行节点脚本时,您可以看到使用npm run start 时通常不会出现的各种调试信息。

在您的情况下,似乎在 dev 模式下,FCM ID 令牌被记录到控制台。

要以类似的方式将令牌记录到控制台,您可以使用以下代码:

const messaging = firebase.messaging();

messaging.getToken()
  .then((currentToken) => {
    console.log("Current FCM ID Token: " + (currentToken || "UNAVAILABLE"))
  }), (err) => {
    console.error(err)
  });

虽然日志记录对于调试很有用,但请使用 getToken() 而无需在生产代码的控制台中记录它。

FCM Documentation 和它的示例项目firebase/quickstart-js/messaging 有关于该主题的更多信息和示例代码。

【讨论】:

    猜你喜欢
    • 2020-04-01
    • 1970-01-01
    • 2019-09-13
    • 2021-03-08
    • 1970-01-01
    • 2019-12-18
    • 2020-09-13
    • 2018-06-01
    • 1970-01-01
    相关资源
    最近更新 更多