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


    }) 

firebaseアプリがありますが、私のデータベースにユーザーがいるかどうかを確認したいのですが、ライセンス契約を表示したくない場合は私も持っていない。現在の方法は、2人のユーザーがいる場合にのみ機能します。事前にあなたの助けをありがとう。ユーザーが既に存在するかどうかを確認するFirebase swift 3.0

答えて

2

私はすべてを行う必要が.VALUEする.ChildAddedを変更され

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

それを考え出しました。これにより、起動時にデータを確実に読み取ることができます。

関連する問題