簡體   English   中英

將phonegap-plugin-push插入Firebase

[英]plug phonegap-plugin-push to Firebase

我的環境迅速: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服務” +本地推送通知(“ phonegap推送”

問題:

  • 步驟1:從理論上講,是否可以在“ phonegap服務實例”中接收Firebase notif
  • 第2步:正確配置Firebase注冊僅需要“ google-services.json”文件

非常感謝

步驟1:從理論上講,是否可以在“ phonegap服務實例”中接收Firebase notif

不,不是,您必須構建應用程序並將apk安裝在設備上

第2步:正確配置Firebase注冊僅需要“ google-services.json”文件

是。 關於phonegap 8的事情:

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

“ app /”很重要。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM