我试图简单地从我的 firebase 数据库中获取所有具有等于我的 postId 的子值的通知。我知道它确实存在,如果我尝试几次它最终会返回快照。这可能是什么问题?
let ref = Database.database().reference().child("notification").child(postUserId).queryOrdered(byChild: postId).queryEqual(toValue: postId)
ref.observeSingleEvent(of: .value) { (snapshot) in
print(snapshot.value)
}
最佳答案
改变这个:
let ref = Database.database().reference().child("notification").child(postUserId).queryOrdered(byChild: postId).queryEqual(toValue: postId)
进入这个:
let ref = Database.database().reference().child("notification").child(postUserId).queryOrdered(byChild: "postId").queryEqual(toValue: postId)
在查询中为postId
添加引号
关于ios - Swift firebase 快照在数据存在时返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59284030/