2017-01-25 9 views
0

私のアプリでは、ユーザーが既にログインしているかどうかに応じて異なるViewControllerを表示します。現在のVC_Aにログインしていない場合は、VC_Bを表示します。その(ヒントはコードのコメントである)のようなユーザーに基づくView Controllerの表示Firebaseログイン状態

if let user = FIRAuth.auth()?.currentUser { 

     let vc = self.storyboard?.instantiateViewController(withIdentifier: "vc_home") as! ViewController_Home 
     self.present(vc, animated: true, completion: nil) 

    } else { 

    // Do Nothing 

    } 
+0

ブロックされたelseブロックの元のコードは、「何もしない」よりもこの情報に有益でした – muescha

+0

Firebaseトークンの有効期限をどのように処理していますか? – Jay

+0

私はほぼ同じ働きをしています。 FIRAuth.auth()?。CurrentUserに= nilの{ self.performSegue(withIdentifier: "signInToTabbarVC"、送信者:ゼロ) }もし! –

答えて

1

は、あなたがそれを行うことができます:私は私のvc_loginに次のコードを試してみました

if FIRAuth.auth()?.currentUser?.uid == nil { 
    // user is not logged in 
    // present VC_B 
} else { 
    // user is logged in 
    // present VC_A 
} 

それとも、このように三項条件演算子を使用することができます。

FIRAuth.auth()?.currentUser?.uid == nil ? presentViewControllerB() : presentViewControllerA() 

func presentViewControllerA() { 
    // call if logged in 
} 

func presentViewControllerB() { 
    // call if not logged in 
} 
関連する問題