I have been battling to get this to work. I have written a function to try and check if the user is logged in or not and if they are not they will be presented with a login screen but I keep getting an error that the Attempt to present....whose view is not in the window hierarchy! and it displays the default storyboard, here is the code below
func checkuser () {
let currentUser = FIRAuth.auth()?.currentUser
if currentUser != nil {
self.view.window?.rootViewController = storyboard?.instantiateViewController(withIdentifier: "eventsstoryboard")
print("user logged in")
}
else
{
let vc = storyboard?.instantiateViewController(withIdentifier: "loginvc") as! loginviewcontroller
self.present(vc,animated: true, completion: nil)
print("user not logged in")
}
}
checkuser()