【问题标题】:ionic firebase.getToken() always return null on android API 23 6.0.0 but not in other version androidionic firebase.getToken() 在 android API 23 6.0.0 上总是返回 null,但在其他版本的 android 中不返回
【发布时间】: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


【解决方案1】:

你跑到模拟器,请确保你在模拟器上安装了google play服务

【讨论】:

    【解决方案2】:

    感谢@Eggy Sudianto 提示我们正确的方向。

    对我们来说问题是我们的根设备甚至没有 google play 服务,这意味着插件工作但没有收到任何令牌。切换设备实际上为我们解决了问题。

    【讨论】:

      猜你喜欢
      • 2020-06-24
      • 2020-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-31
      • 2018-01-16
      • 2012-12-25
      • 1970-01-01
      相关资源
      最近更新 更多