我在过去两天内遇到了离子火基模块(https://ionicframework.com/docs/native/firebase/)的问题。
我不明白为什么我的firebase令牌在app.component.ts
的以下代码部分中始终为NULL:
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()
我的令牌变为空字符串
我运行以下命令来安装我的插件:
$ 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))
,它给了我以下字符串{}
感谢阅读:)
编辑:
我发现它是最近的,但在firebase API中。我不得不用git repo的HEAD
更新我的包答案 0 :(得分:0)
尝试离子2中的代码
import { Platform } from 'ionic-angular';
import { Firebase } from '@ionic-native/firebase';
constructor(public platform: Platform,private cordovaFirebase: Firebase) {
platform.ready().then(() => {
StatusBar.styleDefault();
Splashscreen.hide();
this.cordovaFirebase.grantPermission();
this.cordovaFirebase.getToken().then(token => {
console.log("token....",token)
}).catch(error => console.log(error));
});
}
答案 1 :(得分:0)
cordova-pugin-firebase在cordova ver:7.0.0中被破坏
使用以下任何方法进行修复。
https://github.com/arnesson/cordova-plugin-firebase/pull/570
cordova android版本7及更高版本的安装命令:
cordova plugin add cordova-plugin-firebase --variable ANDROID_VERSION=7x --save
cordova android版本6及以下版本的安装命令:
cordova plugin add cordova-plugin-firebase --variable ANDROID_VERSION=6x --save
或
https://github.com/arnesson/cordova-plugin-firebase/issues/558
更新以下文件中的stringsXml:
plugins / cordova-plugin-firebase / scripts / after_prepare.js第51行 node_modules / cordova-plugin-firebase / scripts / after_prepare.js第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'