I'm working on a swift iPhone application using Parse for the backend and when I restart the app the currentUser
isn't recognized and returns nil redirecting to the login page. Once I sign back in the user stays logged in until I stop the app.
if PFUser.currentUser() == nil {
//return to the login page
} else {
// perform normal operations
}
I'm curious why this is happening since the only place I have PFUser.logOut()
is in a logout function which is not on the initial view controller and only called when a button is pressed. Thanks in advance for the help!
EDIT : This problem began occurring this morning. The past 2 weeks I haven't had any issues regarding automatic login with parse. So I don't know what I could have done to cause it. The only code I changed between last night and this morning was trying to pass data from one view controller to a popoverViewController by adding delegates to my VC's but I have since deleted them and am still at a loss.
I ended up downloading the latest Parse SDK and it solved the problem. Eddy from this post PFUser currentUser nil after app update also said reverting to a previous Parse SDK also solved the issue.
I think you should place this code in the AppDelegate into the method applicationDidBecomeActive() , something like the following:
func applicationDidBecomeActive(application: UIApplication)
{
if PFUser.currentUser() == nil{
// show main screen
var storyboard :UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var LoginScreen = storyboard.instantiateViewControllerWithIdentifier("loginShow") as! UIViewController
UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(LoginScreen, animated: true, completion: nil)
}
else
{
//show login screen
var storyboard :UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var MainScreenNavigation = storyboard.instantiateViewControllerWithIdentifier("TotalMainViewController") as! UIViewController
UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(MainScreenNavigation, animated: false, completion: nil)
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.