我使用firebase作为后端,我想要所有状态为false的用户id。
ios - Swift 3如何在Firebase中获取特定的用户ID-LMLPHP
我在代码中尝试的是:-

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)
                }
            }
        }
    }

最佳答案

在下面找到示例代码。只需验证语法一次。

   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
               }
            }
        }
    }
}

关于ios - Swift 3如何在Firebase中获取特定的用户ID,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47530558/

10-08 21:22