简体   繁体   中英

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)

At that time :

  • I manage to receive push notification generated from my local machine via "phonegap push " in the phonegap simulator
  • I can't receive push notif from Firebase in the phonegap simulator (is it possible ?)
  • 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)

My code (VueJS framework)

  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 "

Questions :

  • step 1 : is it theoricaly possible to receive Firebase notif in a "phonegap serve instance"
  • step 2 : is just "google-services.json" file required to correctly configure the firebase registration

Thanks a lot

step 1 : is it theoricaly possible to receive Firebase notif in a "phonegap serve instance"

No it's not, you have to build the app and install the apk on the device

step 2 : is just "google-services.json" file required to correctly configure the firebase registration

Yes. Just on thing for phonegap 8 :

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

the "app/" is important.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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