首页 > 解决方案 > FirebaseX 没有 firebaseInstanceId

问题描述

我有这样的后端 API:

      registerFcmToken(userIdToken: string, firebaseInstanceId: string, fcmToken: 
string): Promise<ConfirmationResponseModel> {
        // code
      }

你能告诉我我应该在这里寄什么吗?firebaseInstanceId

我在这里使用 FirebaseX 插件:https ://github.com/dpa99c/cordova-plugin-firebasex#api

我可以生成 this.fcmToken = await this.firebase.getToken();但是什么是firebaseInstanceId

Firebase 文档这样说:https ://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId.html#public-taskinstanceidresult-getinstanceid-

但是 FirebaseX 的等价物是什么?

标签: typescriptfirebasefirebase-cloud-messagingcordova-pluginsionic4

解决方案


如果你检查代码,你可以看到有一个方法叫做getId()

https://github.com/dpa99c/cordova-plugin-firebasex/blob/master/www/firebase.js#L14

exports.getId = function (success, error) {
  exec(success, error, "FirebasePlugin", "getId", []);
};

此方法正在调用getId()java 类中的方法FirebasePlugin

     private void getId(final CallbackContext callbackContext) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                try {
                    String id = FirebaseInstanceId.getInstance().getId();
                    callbackContext.success(id);
                } catch (Exception e) {
                    handleExceptionWithContext(e, callbackContext);
                }
            }
        });
    }

https://github.com/dpa99c/cordova-plugin-firebasex/blob/master/src/android/FirebasePlugin.java#L392

所以基本上this.firebase.getId()应该给你实例ID


推荐阅读