【问题标题】:Ionic 2 - firebase plugin - not able to get phone's tokenIonic 2 - firebase 插件 - 无法获取手机的令牌
【发布时间】: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 生成电话令牌不需要特殊设置吗?

标签: angular firebase ionic2


【解决方案1】:

我的 google-services.json 错误。我想我已经创建了一个新项目,但我一定没有用新/当前项目替换 google-services.json。

【讨论】:

    猜你喜欢
    • 2019-08-11
    • 2017-12-06
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    • 2018-03-16
    • 1970-01-01
    • 2019-12-26
    • 2016-07-10
    相关资源
    最近更新 更多