Ionic 2 - firebase 插件 - 无法获取 phone 的令牌
Ionic 2 - firebase plugin - not able to get phone's token
我正在使用这个插件:https://github.com/arnesson/cordova-plugin-firebase 我在 home.html 上有一个按钮调用 home.ts
中的 test() 函数
public test(): void {
// wrap in the platform.ready && platform.is('cordova')
this.fcm.getToken()
.then((token: any) => {
console.log("token: ", token);
});
this.fcm.onTokenRefresh()
.subscribe((token: any) => {
console.log("token onTokenRefresh: ", token);
});
}
当我进入主屏幕时,一切都应该已经初始化,我应该能够从 getToken() 函数中获取令牌。但是我得到了 token: undefined 在我的 console.log 中。我没有收到任何错误,日志是干净的,即没有生成关于这个特定插件的错误。
更新 1:
import { Firebase } from '@ionic-native/firebase';
constructor(public navCtrl: NavController
, public fcm: Firebase) {
更新二:
试过这样的:
cordova插件添加https://github.com/arnesson/cordova-plugin-firebase --variable ANDROID_VERSION=7.1.0 --save
但它仍然是空的。
private void getToken(final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
String token = FirebaseInstanceId.getInstance().getToken();
System.out.println("token: " + token); // null....
callbackContext.success(token);
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
}
});
}
以上方法未获取令牌。所以这似乎不是科尔多瓦问题?
我的google-services.json错了。我想我创建了一个新项目,但我一定没有用 new/current 项目替换 google-services.json。
我正在使用这个插件:https://github.com/arnesson/cordova-plugin-firebase 我在 home.html 上有一个按钮调用 home.ts
中的 test() 函数public test(): void {
// wrap in the platform.ready && platform.is('cordova')
this.fcm.getToken()
.then((token: any) => {
console.log("token: ", token);
});
this.fcm.onTokenRefresh()
.subscribe((token: any) => {
console.log("token onTokenRefresh: ", token);
});
}
当我进入主屏幕时,一切都应该已经初始化,我应该能够从 getToken() 函数中获取令牌。但是我得到了 token: undefined 在我的 console.log 中。我没有收到任何错误,日志是干净的,即没有生成关于这个特定插件的错误。
更新 1:
import { Firebase } from '@ionic-native/firebase';
constructor(public navCtrl: NavController
, public fcm: Firebase) {
更新二: 试过这样的: cordova插件添加https://github.com/arnesson/cordova-plugin-firebase --variable ANDROID_VERSION=7.1.0 --save 但它仍然是空的。
private void getToken(final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
String token = FirebaseInstanceId.getInstance().getToken();
System.out.println("token: " + token); // null....
callbackContext.success(token);
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
}
});
}
以上方法未获取令牌。所以这似乎不是科尔多瓦问题?
我的google-services.json错了。我想我创建了一个新项目,但我一定没有用 new/current 项目替换 google-services.json。