(新 Firebase Unity SDK)在查询上调用 GetValueAsync 不会在第一次调用时触发其 ContinueWith [英] (New Firebase Unity SDK) Calling GetValueAsync on a Query wont fire its ContinueWith the first time its called

查看:22
本文介绍了(新 Firebase Unity SDK)在查询上调用 GetValueAsync 不会在第一次调用时触发其 ContinueWith的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的 Firebase Unity SDK 在我的游戏中建立一个高分,但在尝试更新我的高分列表时遇到了一些问题.这是我尝试更新我的高分列表时运行的代码.

I am building a highscore in my game using the new Firebase Unity SDK but I've run into some problems while trying to update my highscore-list. This is the code Im running when trying to update my highscore list.

public void GetHighscore(Action<DataSnapshot> callback) {
    highscoreRef.OrderByChild("total_score").LimitToLast(10).GetValueAsync().ContinueWith(task => {
        if (task.IsFaulted) {
            // Handle the error...
            Debug.Log(task.Exception.Message);
        }
        else if (task.IsCompleted) {
            callback(task.Result);
        }
    });
}

第一次调用 GetHighscore 时,它​​永远不会进入 ContinueWith 中的 lambda 函数.但是,我第二次调用它时,它会进入 lambda 函数并按预期工作.

The first time GetHighscore gets called it will never enter the lambda function inside ContinueWith. However, the second time I call it, it will enter the lambda function and work as expected.

我在这里做错了什么?

推荐答案

Firebaser here...

Firebaser here...

更新:我确实在这里看到了一个问题,我们将在下一个 Beta 版本中更正.如果您有复杂的查询,没有设置任何索引并且没有数据,则处理该事件时会出错(但是,一旦您获得任何数据,您最终将获得一个事件).

Update: I do see an issue here we will correct in our next Beta release. If you have complex queries, do not have any indices set up and have no data, there is an error handling the event (you will however eventually get a single event once you get any data).

在我们解决此问题之前,您可以通过在目标路径下至少包含一些数据或添加索引来解决此问题 (https://firebase.google.com/docs/database/security/indexing-data).我确定前者有效,但尚未验证后者的解决方法.

Until we fix this, you may be able to work around the issue by having at least some data under the target path or adding an index (https://firebase.google.com/docs/database/security/indexing-data). I'm sure the former works, but haven't verified the latter workaround.

我没有看到你所看到的.我会仔细检查您是否正在处理在您的回调中说结果可能为空或为空的情况.我们的支持人员擅长与您一起解决问题.

I am not seeing what you are seeing. I would double check that you are handling cases where say the Result might be null or empty in your callback. Our support folks are good at walking through issues with you.

https://firebase.google.com/support/contact/troubleshooting/

FirebaseDatabase.DefaultInstance.RootReference.OrderByChild("total_score").LimitToLast(10)
  .GetValueAsync().ContinueWith(x => {
    if (x.Result == null) {
      Debug.Log("null!");
    } else if (!x.Result.HasChildren) {
      Debug.Log("no children!");
    } else {
      foreach (var child in x.Result.Children) {
        Debug.Log(child.ToString());
      }
    }
  });

这篇关于(新 Firebase Unity SDK)在查询上调用 GetValueAsync 不会在第一次调用时触发其 ContinueWith的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆