0
let database = FIRDatabase.database().reference()
    database.child("Users").queryOrderedByKey().observe(.childAdded, with: { (snapshot) in
        print(snapshot)
        if let value = snapshot.value as? [String: AnyObject] {
            let ui = value["id"] as! String
            if ui != FIRAuth.auth()!.currentUser!.uid
            {
                var storyboard = UIStoryboard(name: "Main", bundle: nil)
                if s == true
                {
                    storyboard = UIStoryboard(name: "Main", bundle: nil)
                }
                else if p == true
                {
                    storyboard = UIStoryboard(name: "big", bundle: nil)
                }
                else if se == true
                {
                    storyboard = UIStoryboard(name: "se", bundle: nil)
                }
                else if os == true
                {
                    storyboard = UIStoryboard(name: "4s", bundle: nil)
                }
                else if ip1 == true
                {
                    storyboard = UIStoryboard(name: "ipad1", bundle: nil)
                }
                else if ipb == true
                {
                    storyboard = UIStoryboard(name: "ipadbig", bundle: nil)
                }

                        let naviVC = storyboard.instantiateViewController(withIdentifier: "eula")as! UIViewController
                        let appDelegate = UIApplication.shared.delegate as! AppDelegate
                        appDelegate.window?.rootViewController = naviVC

            }
            else
            {
                var storyboard = UIStoryboard(name: "Main", bundle: nil)
                if s == true
                {
                    storyboard = UIStoryboard(name: "Main", bundle: nil)
                }
                else if p == true{
                    storyboard = UIStoryboard(name: "big", bundle: nil)
                }
                else if se == true
                {
                    storyboard = UIStoryboard(name: "se", bundle: nil)
                }
                else if os == true{
                    storyboard = UIStoryboard(name: "4s", bundle: nil)
                }
                else if ip1 == true
                {
                    storyboard = UIStoryboard(name: "ipad1", bundle: nil)
                }
                else if ipb == true
                {
                    storyboard = UIStoryboard(name: "ipadbig", bundle: nil)
                }
                let naviVC = storyboard.instantiateViewController(withIdentifier: "yo")as! UIViewController
                let appDelegate = UIApplication.shared.delegate as! AppDelegate
                appDelegate.window?.rootViewController = naviVC
            }
        }


    })

我有一个firebase应用程序,我想检查我的数据库中是否存在用户,如果我不想显示许可协议,但如果他们这样做我也没有。我当前的方法只有在有两个用户时才有效。提前谢谢你的帮助。

4

3 回答 3

1

您需要做的就是将 .ChildAdded 更改为 .value。这将确保它在您开始时读取数据。

于 2018-01-09T14:24:12.027 回答
1

我想到了

  let database = FIRDatabase.database().reference()
    database.child("Users").observeSingleEvent(of: FIRDataEventType.value, with: { (snapshot) in
        print(snapshot)

        if snapshot.hasChild( FIRAuth.auth()!.currentUser!.uid)
            {
于 2017-03-13T23:28:05.567 回答
0

使用该代码,我认为它只会在添加孩子时执行。我现在无法检查,但请尝试

database.child("Users").queryOrderedByKey().observe(.Value, with:{ (snapshot) in
            ...
    })

正如我所说,我无法检查它,所以如果您有任何问题,请回答我。祝你好运!

于 2017-03-13T15:30:17.653 回答