Ionic Firebase令牌始终为null,并且不刷新令牌 [英] Ionic firebase token alway null and no token refresh

查看:77
本文介绍了Ionic Firebase令牌始终为null,并且不刷新令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用离子火力基础模块( https://ionicframework.com/docs/最近2天.

i'm in trouble with ionic firebase module (https://ionicframework.com/docs/native/firebase/) during the last 2 days.

在以下app.component.ts中的代码部分中,我不明白为什么我的Firebase令牌始终为NULL:

I don't understand why my firebase token is alway NULL in the following code section in app.component.ts :

this.platform.ready().then(() => {
  this.firebase.getToken().then(firebaseTokenSuccess).catch(firebaseTokenFailure);

  this.firebase.onTokenRefresh().subscribe(firebaseTokenRefresh);

  function firebaseTokenRefresh(tkn) {
    return alert("New token received: " + JSON.stringify(tkn));
  }

  function firebaseTokenSuccess(tkn) {
    return alert("Token access success: " + JSON.stringify(tkn));
  }

  function firebaseTokenFailure(e) {
    return alert("Token access failure: " + e.toString());
  }
});

如果在准备好的块开始时我有grantPermission(),则我的令牌将成为一个空字符串

If i had grantPermission() at the beggining of the ready block my token become an empty string

我运行了以下命令来安装我的插件:

I ran the following command to install my plugin :

$ ionic plugin rm cordova-plugin-firebase

$ npm install @ionic-native/push --save

这是我的插件列表:

$ ionic plugins                        
com.googlemaps.ios 2.4.0 "Google Maps SDK for iOS"
cordova-android-play-services-gradle-release 1.1.1 "cordova-android-play-services-gradle-release"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-console 1.1.0 "Console"
cordova-plugin-device 1.1.6 "Device"
cordova-plugin-facebook4 1.9.1 "Facebook Connect"
cordova-plugin-file 4.3.3 "File"
cordova-plugin-file-transfer 1.6.3 "File Transfer"
cordova-plugin-firebase 0.1.24 "Google Firebase Plugin"
cordova-plugin-googlemaps 1.4.5 "cordova-googlemaps-plugin"
cordova-plugin-inappbrowser 1.7.1 "InAppBrowser"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.3 "StatusBar"
cordova-plugin-whitelist 1.3.2 "Whitelist"
ionic-plugin-keyboard 2.2.1 "Keyboard"

这是我的项目架构:

$ tree -L 1  
.
├── appli_dev.keystore
├── bower_components
├── build.gradle
├── config.xml
├── GoogleService-Info.plist
├── google-services.json
├── hooks
├── init.sh
├── ionic.config.json
├── node_modules
├── package.json
├── package-lock.json
├── platforms
├── plugins
├── README.md
├── resources
├── src
├── tsconfig.json
├── tslint.json
└── www

添加了alert(JSON.stringify(this.firebase))行,这给了我以下字符串{}

Iadded the line alert(JSON.stringify(this.firebase)) which give me the following string {}

感谢您的阅读:)

我发现这是最新的,但是在Firebase API中.我不得不用git repo的HEAD更新我的包

I found out that it was a recent but in firebase API. I had to update my package with git repo's HEAD

推荐答案

cordova-pugin-firebase在cordova ver:7.0.0中已损坏

The cordova-pugin-firebase is broken in cordova ver:7.0.0

使用以下任何一种方法对其进行修复.

Use any of the following methods for fixing it.

https://github.com/arnesson/cordova-plugin-firebase/pull/570

cordova android 7及更高版本的安装命令:

Installation command for cordova android version 7 and above:

cordova plugin add cordova-plugin-firebase --variable ANDROID_VERSION=7x --save

cordova android 6及更低版本的安装命令:

Installation command for cordova android version 6 and below:

cordova plugin add cordova-plugin-firebase --variable ANDROID_VERSION=6x --save

https://github.com/arnesson/cordova-plugin-firebase/issues/558

更新以下文件中的stringsXml:

Update the stringsXml in the following files:

plugins/cordova-plugin-firebase/scripts/after_prepare.js第51行 node_modules/cordova-plugin-firebase/scripts/after_prepare.js第51行

plugins/cordova-plugin-firebase/scripts/after_prepare.js line 51 node_modules/cordova-plugin-firebase/scripts/after_prepare.js line 51

-       stringsXml: ANDROID_DIR + '/res/values/strings.xml' 
+       stringsXml: fileExists(ANDROID_DIR + '/app/src/main/res/values/strings.xml') ? ANDROID_DIR + '/app/src/main/res/values/strings.xml' : ANDROID_DIR + '/res/values/strings.xml' 

这篇关于Ionic Firebase令牌始终为null,并且不刷新令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆