1

新規作成しましたFirebaseログイン。データベースには2つのカテゴリがあります。 "クック"と "顧客"。 「Cooks」にはCookViewControllerがあり、「Customers」にはcustomerViewControllerがあります。このメールがどのカテゴリに属しているかを知る必要があります。ログイン後、segueCookViewControllerまたはCustomerViewControllerになります。以下はログイン用のコードですが、メールがどのカテゴリに属しているかを知る方法はわかりません。ありがとう!以下のようにFirebaseログインする電子メールを確認する方法は、データベースのどのカテゴリに属していますか?

@IBAction func loginPressed(sender: AnyObject) { 

    if let email = emailField.text where email != "", let password = passwordField.text where password != "" { 

     FIRAuth.auth()?.signInWithEmail(email, password: password, completion: { (user, err) in 

     if err != nil { 

     print(err) 

      } else { 

     // Here I need to know whcih view Controller to Segue to: 

      self.performSegueWithIdentifier(identifier: String, sender: self) 

       } 

} 

データ構造:

enter image description here

答えて

3

どのようなあなたのJSONを作りについて: -

yourApp:{ 
cooks:{ 
     email1:true, 
     email3:true, 
     email4:true, 
     email7:true, 
     email8:true}, 
customers:{ 
     email2:true, 
     email12:true, 
     email13:true, 
     email4:true, 
     email8:true}, 
users:{ 
     uid1:{ 
      email : [email protected], 
      isCook: true 
      }, 

     uid2:{ 
      email : [email protected], 
      isCook: false 
      }.... 
      } 
     } 

ですから、コックセクションまたは顧客のセクションで確認することができますいずれか、またはユーザセクションの下にあるユーザ自身、次にisCookノードに関連する場合、 - > cookViewControllerに移動し、そうでなければcustomerViewControllerに移動します

最も簡単な方法は、UIDにチェックするために、次のようになります -

FIRDatabase.database().reference().child("users/\(FIRAuth.auth()!.currentUser!.uid)/isCook").observeSingleEventOfType(.Value,withBlock:{(snap) in 
    if let isThisUserCook = snap.value as? Bool //or String{ 
      if isThisUserCook == true{ 

       //segue to cookVC 
       }else{ 
       //segue to customerVC 

       } 
      } 
     }) 
+0

こんにちはドラヴィダ、素晴らしいサウンド!試してみましょう。私はあなたの答えを受け入れるでしょう。良い週末を! – developermike

+0

喜んで、あなたの前のコメントを削除...:)\ – Dravidian

関連する問題