I am working to bypass login screen if the current user is not nil. To do this, I followed the recommendation posted here. After running the code, I get a blank white view in the simulator without any errors showing. Here is the code:
storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle());
let currentUser = PFUser.currentUser()
print(currentUser)
if currentUser != nil {
self.window?.rootViewController = storyboard?.instantiateViewControllerWithIdentifier("HomeViewController");
}
Worth mentioning that HomeViewController is based on Tab navigation. What am I missing?
The setup I have is:
I'm assuming your home tab bar controller has the identifier "HomeViewController" and your sign in view controller has the identifier "SignInViewController" and this code is in your didFinishLaunchingWithOptions() AppDelegate method:
storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
if let currentUser = PFUser.currentUser() { // currentUser is not nil
// set up app for valid in user
self.window?.rootViewController = storyboard?.instantiateViewControllerWithIdentifier("HomeViewController")
return true // don't load the rootViewController from your storyboard (if you have an initial view set)
} else { // there is no current user
// set up app for new or non logged in user
self.window?.rootViewController = storyboard?.instantiateViewControllerWithIdentifier("SignInViewController")
return true
}
From your comments, it sounds like you have a navigation controller with its root view controller being your sign in view controller, which is why when you segue to your tab bar controller, you get a navigation bar.
Since with my approach you're not getting the segue (and the sign in view controller's navigation bar), initialize a new UINavigationController and set its rootViewController to be your tab bar controller:
if let currentUser = PFUser.currentUser() { // currentUser is not nil
// load tab bar controller
let tabBarController = storyboard?.instantiateViewControllerWithIdentifier("TabBarViewController")
// initialize a new navigation controller with the tab bar controller as its rootViewController
let navC = UINavigationController(rootViewController: tabBarController)
// set the window's root view controller to be your new navigation controller
self.window?.rootViewController = navC
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With