Reputation: 197
I am trying to avoid the start/login screen overall and go straight to the first page of the app if the user is logged in. Nothing happens when I run the code below. I breakpointed, and it said that the current user is nil, but when the view loads, the current user is not nil.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
var currentUser = PFUser.currentUser()
print("user \(currentUser)")
if currentUser != nil {
if(currentUser?.username?.rangeOfString("@music.co") != nil){
self.storyboard?.instantiateViewControllerWithIdentifier("venuehomescreen")
}else{
self.window?.rootViewController = self.storyboard?.instantiateViewControllerWithIdentifier("userhomescreen")
}
}
}
Upvotes: 0
Views: 18
Reputation: 957
I usually proceed as normal in my application to the log in view controller, than in viewDidAppear of that log in view controller, I add logic similar to the following:
if PFUser.currentUser() != nil{
//perform segue
//or present view controller modally
}
It's important to have your log in view controller in the heiarchy for cases such as logging out which enables you to just unwind to the log in view controller.
Also, it's necessary to perform a segue in viewDidAppear because you must perform view controller transitions only after the view controller you're transitioning from has been added to the heiarchy.
Upvotes: 0