我正在开发一个使用Parse作为后端的快速iPhone应用程序,当我重新启动应用程序时,currentUser
不被识别,并返回nil重定向到登录页面。一旦我重新登录,用户就会保持登录状态,直到我停止应用程序。
if PFUser.currentUser() == nil {
//return to the login page
} else {
// perform normal operations
}
我很好奇为什么会发生这种情况,因为我有PFUser.logOut()
的唯一地方是在注销函数,这不是在初始视图控制器上,只有在按下按钮时才调用。提前感谢您的帮助!
EDIT:这个问题今天早上开始发生。过去的2周我没有任何问题,关于自动登录与解析。所以我不知道我做了什么导致了这一切。我在昨晚和今天早上之间改变的唯一代码是试图通过向我的VC添加委托来将数据从一个视图控制器传递到popoverViewController,但我已经删除了它们,并且仍然处于亏损状态。
我最终下载了最新的Parse SDK,它解决了这个问题。Eddy从这个帖子PFUser currentUser nil在应用程序更新后也说恢复到以前的Parse SDK也解决了这个问题。
我认为你应该把这段代码在AppDelegate放到方法applicationDidBecomeActive()中,就像下面这样:
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)
}
}