【发布时间】:2019-01-12 10:38:33
【问题描述】:
我正在使用这个插件: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() 函数中获取令牌。但是我在我的 console.log 中得到了令牌:未定义。我没有收到任何错误,日志是干净的,即没有针对此特定插件生成错误。
更新 1:
import { Firebase } from '@ionic-native/firebase';
constructor(public navCtrl: NavController
, public fcm: Firebase) {
更新 2: 像这样尝试: 科尔多瓦插件添加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());
}
}
});
}
上述方法未获取令牌。所以这似乎不是科尔多瓦的问题?
【问题讨论】:
-
"请注意,如果尚未建立令牌,则令牌将为空。"可能是服务器端问题?
-
好的。这是什么意思?
-
没有。当我什至没有令牌时,这怎么可能是服务器端问题?
-
您是否设置了 Firebase 以生成令牌?
-
Firebase 生成电话令牌不需要特殊设置吗?