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


    }) 

我有一个火力点应用程序,我要检查,如果一个用户在我DATABSE存在,如果没有我想要显示的许可协议,但如果他们这样做我也没有。我目前的方法只适用于有两个用户。提前谢谢你的帮助。检查用户是否已经存在火力地堡SWIFT 3.0

回答

2

我想通了

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

     if snapshot.hasChild(FIRAuth.auth()!.currentUser!.uid) 
      { 
1

有了这段代码,我认为它只会在添加子项时执行。我不能检查出来,但现在与

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

尝试正如我所说的,我不能签这样回答我,如果你有任何问题。祝你好运!

+0

@AtaerCaner .Value崩溃了我的应用程序 –

+0

是的,我没有记得它,但它必须与.Value在你的情况。 –

+0

雅我意识到它必须是在我发布后的价值 –

2

所有你需要做的是改变.ChildAdded到.value的。这将确保您在开始时读取数据。