首页 > 解决方案 > 将 phonegap-plugin-push 插入 Firebase

问题描述

快点我的环境:Phonegap 8.0.0 phonegap-plugin-push 2.1.2(最后一个版本不兼容phonegap 8.0.0)

当时 :

我的代码(VueJS 框架)

  console.log('calling push init');
  window.gtvapp.push = PushNotification.init({
    'android': {
      // 'senderID': 'XXXXXXXX'
    },
    'browser': {},
    'ios': {
      'sound': true,
      'vibration': true,
      'badge': true,
      'alert': true
      // 'senderID': 'xxxxxxxx'
    },
    'windows': {}
  })
  console.log('after init')
  window.gtvapp.push.on('registration', function(data) {
    console.log('registration event: ' + data.registrationId)
    var oldRegId = window.localStorage.getItem('registrationId')
    if (oldRegId !== data.registrationId) {
      window.localStorage.setItem('registrationId', data.registrationId)
      // Post registrationId to your app server as the value has changed
      // TODO
    }
  })
  window.gtvapp.push.on('error', function(e) {
      console.log('push error = ' + e.message)
  })

// (...)

let router = this.$router
window.gtvapp.push.on('notification', function(data) {
  console.log('notification event')
  console.log(JSON.stringify(data))
  if (device.platform === 'Android') {
    navigator.notification.alert(
      data.message,         // message
      function() {
        console.log(window.location.pathname)
        console.log(data.additionalData.path)
        // window.localStorage.setItem('pushpath', data.additionalData.path)
        router.push(data.additionalData.path)
      },
      data.title,
      'En savoir plus'
    )
  }
})

此代码在模拟器“phonegap serve”+本地推送通知“phonegap push”上完美运行

问题 :

非常感谢

标签: javascriptcordovafirebasephonegap

解决方案


第 1 步:理论上是否可以在“phonegap 服务实例”中接收 Firebase 通知

不,不是,您必须构建应用程序并在设备上安装 apk

第 2 步:只是正确配置 firebase 注册所需的“google-services.json”文件

是的。就在 phonegap 8 上:

<platform name="android">
  <resource-file src="google-services.json" target="app/google-services.json" />
</platform>

“app/”很重要。


推荐阅读