c# - Firebase GetValueAsync() 如果 task.result 不存在它不执行下面的代码
问题描述
我在 Unity 游戏上有这个功能,它在计算机上运行良好,但在移动设备上却没有。问题是 bool snap 将是错误的代码不会执行下面的任何行DataSnapshot snapshot = task.Result;
。但如果DataSnapshot snapshot = task.Result;
返回 1 个结果,它工作正常。
void CheckUser()
{
reference.Child("Stars").Child("Users").Child(login).LimitToFirst(1)
.GetValueAsync().ContinueWith(task =>
{
if (task.IsFaulted || task.IsCanceled)
{
info.text = "falha";
}
else if (task.IsCompleted)
{
//info.text = task.Result.ToString();
DataSnapshot snapshot = task.Result;
//info.text = snapshot.ToString();
bool snap = snapshot.Exists;
info.text = snap.ToString();
if (snap)
{
info.text = "login existente, selecione outro sff";
}
else
{
info.text = "falha 4 ";
writeLogin();
}
// Do something with snapshot...
}
else
{
info.text = "falha 3 ";
}
}
);
}
解决方案
void CheckUser()
{
reference.Child("Stars").Child("Users")
.GetValueAsync().ContinueWith(task =>
{
if (task.IsFaulted || task.IsCanceled)
{
info.text = "Verifique a Internet e tente de novo";
}
else if (task.IsCompleted)
{
//info.text = task.Result.ToString();
IDictionary snapshot = (IDictionary) task.Result.Value;
bool snap = false;
if (snapshot[login]!= null)
{
snap = true;
}
Debug.Log(snap.ToString());
if (snap)
{
info.text = "login existente, selecione outro sff";
}
else
{
//info.text = "falha 4 ";
writeLogin();
}
// Do something with snapshot...
}
else
{
info.text = "Verifique a Internet e tente de novo";
}
});
}
推荐阅读
- git - 错误:指定了主线,但提交不是合并;致命:还原失败
- jax-rs - 为什么即使我声明了某个包,jax-rs 仍在扫描我的所有包?
- amazon-web-services - 如何添加 AWS Auth 以打开 api 规范?
- javascript - 如何测试请求的方法是否为 POST 或不使用 API(邮递员)中的旧 JS 方法
- amazon-web-services - 无法从 Glue 写入 S3
- python - 如何拆分 Cora 数据集以仅在训练部分训练 GCN 模型?
- python - 循环尝试创建字典的列表
- php - CodeIgniter 4 错误验证未读取
- python - Django,如何通过 Windows 任务计划程序运行命令
- python - 从条目小部件获取数据时的范围问题