为什么我没有收到firebase消息?

时间:2017-02-23 01:32:54

标签: javascript firebase firebase-cloud-messaging

我看到我的服务器正在将消息正确发送到firebase API,因为它返回成功:1 响应但我的客户端没有收到消息,发生了什么,我的代码是:

  const messaging = firebase.messaging()
  const that = this

  messaging.requestPermission()
  .then(function() {
    return messaging.getToken()
  })
  .then(function(token) {
    that.updateServerFirebaseToken(token)
  })
  .catch(function(err) {
    console.log(err)
  })

  // Call to user
  messaging.onMessage(function(payload) {
    console.log('firebase', payload)
    if(payload.data.status == 'calling') {
      this.audio.play()
      this.$store.commit(types.CALLING, JSON.decode(payload.data.order))
    }
  })

和我的服务人员firebase-messaging-sw.js

const messaging = firebase.messaging()

messaging.setBackgroundMessageHandler(function(payload) {
  console.log('FIREBASE call', payload);
  if(payload.data.status == 'calling') {
    channel.postMessage(payload.data)

    return self.registration.showNotification('Nuevo pedido', {body: "Llamada para transporte de un pedido"})
  }
})

0 个答案:

没有答案