Swift 3如何在Firebase中获取特定的用户ID [英] Swift 3 How to get specific user id in firebase
本文介绍了Swift 3如何在Firebase中获取特定的用户ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Firebase作为后端,并且我希望所有状态为false的用户ID.
I am using firebase as backend and I want all user id with status false.
我在代码中尝试的内容:-
What I am trying in my code:-
ref.child("users").child((Auth.auth().currentUser?.uid)!).child("status").queryOrdered(byChild: "status").queryEqual(toValue : "false").observe(.value) { (snapshot: DataSnapshot) in
if let snapshot = snapshot.children.allObjects as? [DataSnapshot] {
print("SNAPSHOT: \(snapshot)")
for snap in snapshot {
if let postDict = snap.value as? Dictionary<String, AnyObject> {
let key = snap.key
print(key)
print(postDict)
}
}
}
}
推荐答案
在下面找到示例代码.只需验证一次语法即可.
Find sample code below. Just verify syntax once.
ref.child("users").observe(DataEventType.value, with: { (snapshot) in
if let snapshot = snapshot.children.allObjects as? [DataSnapshot] {
print("SNAPSHOT: \(snapshot)")
for snap in snapshot {
if let userDict = snap.value as? Dictionary<String, AnyObject> {
if userDict["Status"] as? Bool == false {
let key = snap.key
print(key)
//Add this key to userID array
}
}
}
}
}
这篇关于Swift 3如何在Firebase中获取特定的用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文