Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity Firebase RealtimeDatabase GetValueAsync()不返回任何内容_C#_Firebase_Unity3d_Firebase Realtime Database - Fatal编程技术网

C# Unity Firebase RealtimeDatabase GetValueAsync()不返回任何内容

C# Unity Firebase RealtimeDatabase GetValueAsync()不返回任何内容,c#,firebase,unity3d,firebase-realtime-database,C#,Firebase,Unity3d,Firebase Realtime Database,以下代码在Firebase 4.2版中正确执行: public void RetrieveSummary(Action<int[]> onRetrieve) { Debug.Log("FirebaseStorageService - Retrieving Summary from remote..."); string referencePath = string.Format("users/{0}/sum", GetUserID()); FirebaseDa

以下代码在Firebase 4.2版中正确执行:

public void RetrieveSummary(Action<int[]> onRetrieve) {
    Debug.Log("FirebaseStorageService - Retrieving Summary from remote...");
    string referencePath = string.Format("users/{0}/sum", GetUserID());
    FirebaseDatabase.DefaultInstance.GetReference(referencePath).GetValueAsync().ContinueWith(task => {
        if (task.IsCompleted) {
            DataSnapshot snapshot = task.Result;
            if (snapshot.Exists) {
                HammurabiAnalytics.LogCustomEvent("Download_Data_Size", "Summary_User_Data", snapshot.GetRawJsonValue().Length);
                Debug.Log("FirebaseStorageService - Raw Remote Summary Data: " + snapshot.GetRawJsonValue());
                int[] summaryData = JsonConvert.DeserializeObject<int[]>(snapshot.GetRawJsonValue());
                Debug.Log("FirebaseStorageService - Retrieving Summary from remote - DONE");
                onRetrieve(summaryData);
            } else {
                Debug.Log("FirebaseStorageService - User Summary Data is missing!");
                onRetrieve(new int[4]);
            }
        } else {
            Debug.LogError("FirebaseStorageService - RetrieveSummary has failed!");
            onRetrieve(new int[4]);
        }
    });
}
publicsvoidretrievesummary(操作onRetrieve){
Log(“FirebaseStorageService-从远程检索摘要…”);
string referencePath=string.Format(“users/{0}/sum”,GetUserID());
FirebaseDatabase.DefaultInstance.GetReference(referencePath).GetValueAsync().ContinueWith(任务=>{
如果(任务已完成){
DataSnapshot快照=task.Result;
if(snapshot.Exists){
LogCustomEvent(“下载数据大小”、“摘要用户数据”、snapshot.GetRawJsonValue().Length”);
Log(“FirebaseStorageService-原始远程摘要数据:”+snapshot.GetRawJsonValue());
int[]summaryData=JsonConvert.DeserializeObject(snapshot.GetRawJsonValue());
Log(“FirebaseStorageService-从远程检索摘要-完成”);
onRetrieve(汇总数据);
}否则{
Log(“FirebaseStorageService-缺少用户摘要数据!”);
onRetrieve(新的int[4]);
}
}否则{
LogError(“FirebaseStorageService-RetrieveSummary已失败!”);
onRetrieve(新的int[4]);
}
});
}
正确地说,我的意思是执行了ContinueWith,并且我能够使用日志消息等继续该过程。将Firebase版本更新到5.2.1后,我无法继续

为了详细说明这个问题,我可以说ContinueWith中的代码块在引用中没有数据时不会被调用。如果我在引用上创建了一个数据,则检索工作正常。我也不能添加虚拟数据

我也找不到一个解决办法,这太阻碍我了。有什么想法吗?有解决办法吗?有什么解决根本原因的办法吗


Firebase:5.2.1,Unity:2017.2我想我知道这里发生了什么。首先,验证没有调用您的第一个调试日志语句。我想可能是的。最可能发生的情况是,
task.Result
null
,导致抛出异常,阻止其余日志函数执行。由于
ContinueWith
的工作方式,异常只会被默默地消耗掉


您可以通过使用
task.IsFaulted
在获得结果之前检查任务是否出错来解决此问题。完成只是意味着它完成了运行,而不是成功完成,如果不成功,结果不会被填充。

当你说它失败时,你是什么意思?你有错误吗?如果有,是什么?它不会继续。我在Logcat中没有收到任何错误您是说ContinueWith中的代码没有被调用吗?我不知道Unity的编码,但ContinueWith中还有其他代码块吗?没错!ContinueWith中的代码块未被调用。