【问题标题】:plug phonegap-plugin-push to Firebase将 phonegap-plugin-push 插入 Firebase
【发布时间】:2018-09-14 12:37:47
【问题描述】:

快速我的环境: 电话间隙 8.0.0 phonegap-plugin-push 2.1.2(最新版本不兼容phonegap 8.0.0)

当时:

  • 我设法通过 phonegap 模拟器中的“phonegap push”接收本地计算机生成的推送通知
  • 我无法在 phonegap 模拟器中收到来自 Firebase 的推送通知(可能吗?)
  • 当我为 Android 构建应用程序时,由于我的应用程序中的 phonegap-plugin-push 相关代码,她在启动时崩溃(空白页面)(如果我评论它,她会正常启动)

我的代码(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”上完美运行

问题:

  • 第 1 步:理论上是否可以在“phonegap 服务实例”中接收 Firebase 通知
  • 第 2 步:只是正确配置 firebase 注册所需的“google-services.json”文件

非常感谢

【问题讨论】:

    标签: javascript cordova firebase phonegap


    【解决方案1】:

    第 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/”很重要。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-07
      • 1970-01-01
      • 2019-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多