小编eee*_*ttt的帖子

具有Firebase云消息传递的Vue PWA无法正常工作

我正在尝试以下代码:

    navigator.serviceWorker.register('service-worker.js')
      .then((registration) => {
        const messaging = firebase.messaging().useServiceworker(registration)
        console.log(messaging)
        messaging.requestPermission().then(function () {
          console.log('Notification permission granted.')
          messaging.getToken().then(function (currentToken) {
            if (currentToken) {
              console.log(currentToken)
            }
          })
        })
      })
Run Code Online (Sandbox Code Playgroud)

我的清单:

{
  "name": "Herot-Eyes",
  "short_name": "herot-eyes",
  "gcm_sender_id": "103953800507",
  "icons": [
    {
      "src": "/static/img/icons/herot-eyes-192x192.png",
      "sizes": "192x192",
      "type": "image/png"
    },
    {
      "src": "/static/img/icons/herot-eyes-512x512.png",
      "sizes": "512x512",
      "type": "image/png"
    },
    {
      "src": "/static/img/icons/apple-touch-icon-180x180.png",
      "sizes": "180x180",
      "type": "image/png"
    }
  ],
  "start_url": "/",
  "display": "fullscreen",
  "orientation": "portrait",
  "background_color": "#000000",
  "theme_color": "#2196f3"
}
Run Code Online (Sandbox Code Playgroud)

怎么了?我的console.log(messaging)返回工厂错误,如下所示:

bad-push-set:“用于存储/查找的FCM推送集不是有效的推送集字符串。” 不良范围

“服务工作者作用域必须是至少包含一个字符的字符串。” 发件人编号

“请确保在传递给firebase.initializeApp()的选项中正确设置了'messagingSenderId'。” 不良订阅 …

push-notification firebase vue.js service-worker progressive-web-apps

7
推荐指数
1
解决办法
2891
查看次数

生成随机密钥火库

我正在运行一个FIRESTORE数据库,我想创建一个与firestore具有相同模式的随机密钥。

在链接中,我找到了在创建文档时调用的函数:“db.ref.add()”以在客户端生成密钥:

https://github.com/firebase/firebase-js-sdk/blob/73a586c92afe3f39a844b2be86086fddb6877bb7/packages/firestore/src/util/misc.ts#L36

我需要做这样的事情:

let key = newId()
console.log(key)
db.ref().doc(key).set(data)
Run Code Online (Sandbox Code Playgroud)

javascript key firebase google-cloud-firestore

4
推荐指数
2
解决办法
5941
查看次数

Firestore onSnapshot->是否可用于子集合?

Firestore的onSnapshot方法是否由子集合中的任何更改触发?

db.firestore.collection('x')有什么区别。onSnapshot

还有db.firestore.collection('x')。doc('y')。collection('z')。onSnapshot

他们平等吗???

firebase google-cloud-firestore

0
推荐指数
1
解决办法
717
查看次数