简体   繁体   English

将phonegap-plugin-push插入Firebase

[英]plug phonegap-plugin-push to Firebase

Quickly my environment : Phonegap 8.0.0 phonegap-plugin-push 2.1.2 (the last version is not compatible to phonegap 8.0.0) 我的环境迅速:Phonegap 8.0.0 phonegap-plugin-push 2.1.2(最新版本与phonegap 8.0.0不兼容)

At that time : 那时候 :

  • I manage to receive push notification generated from my local machine via "phonegap push " in the phonegap simulator 我设法通过phonegap模拟器中的“ phonegap push”接收从本地计算机生成的推送通知
  • I can't receive push notif from Firebase in the phonegap simulator (is it possible ?) 我无法在phonegap模拟器中从Firebase接收到推送通知(可以吗?)
  • When I build the app for Android, she crash at start (blank page) due to the phonegap-plugin-push associated code in my app (if I comment it, she start normally) 当我为Android开发应用程序时,由于我应用程序中的phonegap-plugin-push相关代码,她在启动时(空白页)崩溃了(如果我发表评论,她将正常启动)

My code (VueJS framework) 我的代码(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'
    )
  }
})

This code works perfectly as attended on simulator "phonegap serve" + local push notif "phonegap push " 此代码在模拟器“ phonegap服务” +本地推送通知(“ phonegap推送”

Questions : 问题:

  • step 1 : is it theoricaly possible to receive Firebase notif in a "phonegap serve instance" 步骤1:从理论上讲,是否可以在“ phonegap服务实例”中接收Firebase notif
  • step 2 : is just "google-services.json" file required to correctly configure the firebase registration 第2步:正确配置Firebase注册仅需要“ google-services.json”文件

Thanks a lot 非常感谢

step 1 : is it theoricaly possible to receive Firebase notif in a "phonegap serve instance" 步骤1:从理论上讲,是否可以在“ phonegap服务实例”中接收Firebase notif

No it's not, you have to build the app and install the apk on the device 不,不是,您必须构建应用程序并将apk安装在设备上

step 2 : is just "google-services.json" file required to correctly configure the firebase registration 第2步:正确配置Firebase注册仅需要“ google-services.json”文件

Yes. 是。 Just on thing for phonegap 8 : 关于phonegap 8的事情:

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

the "app/" is important. “ app /”很重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM