【发布时间】:2018-09-17 14:47:42
【问题描述】:
为什么 firebase.getToken() 在 android API 23 6.0.0 上总是返回 null 而在其他版本的 android 上却没有?我在android nougat,oreo,marsh(6.0.1)上试过,23之前的版本不为null,只在android 6.0.0上
注意:我正在使用插件 cordova-plugin-firebase 1.0.5 (https://github.com/arnesson/cordova-plugin-firebase) 我跑去模拟器genymotion
代码
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
var idtoken: string;
if(this.platform.is('core') || this.platform.is('mobileweb')) {
}else {
this.firebase.getToken().then(token => {
idtoken = token;
alert(token)
}) // save the token server-side and use it to push notifications to this device
.catch(error => {
console.error('Error getting token', error)
});
this.firebase.onTokenRefresh().subscribe((token: string) => {
idtoken = token;
});
}
}
【问题讨论】:
-
控制台中显示任何错误?
-
@Ashvinsolanki 没有错误,只有 null 令牌。我不认为那个链接是这样,因为 firebase 在其他 android 版本上正常工作。令牌 null 仅在 android 6.0.0
-
@E-Place 如果您尝试使用 getIdToken() 而不是 getToken()?
-
@LeonardoGabriel 没有方法
getIdToken()
标签: android firebase ionic-framework