将phonegap-plugin-push插入Firebase

问题描述 投票:0回答:1

快速我的环境:Phonegap 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”+本地推送notif“phonegap push”

问题:

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

非常感谢

javascript cordova firebase phonegap
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.