重启应用后 PFUser currentUser returns nil
PFUser currentUser returns nil after restarting app
我正在为后端使用 Parse 开发 swift iPhone 应用程序,当我重新启动应用程序时,无法识别 currentUser
并且 returns 无重定向到登录页面。一旦我重新登录,用户将保持登录状态,直到我停止该应用程序。
if PFUser.currentUser() == nil {
//return to the login page
} else {
// perform normal operations
}
我很好奇为什么会发生这种情况,因为我唯一拥有 PFUser.logOut()
的地方是在注销功能中,该功能不在初始视图控制器上,仅在按下按钮时调用。在此先感谢您的帮助!
编辑:这个问题是今天早上开始出现的。在过去的 2 周里,我没有遇到任何关于使用 parse 自动登录的问题。所以我不知道我能做些什么来引起它。从昨晚到今天早上,我更改的唯一代码是尝试通过向我的 VC 添加委托来将数据从一个视图控制器传递到 popoverViewController,但我已经删除了它们并且仍然不知所措。
我认为您应该将 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)
}
}
我最终下载了最新的 Parse SDK,它解决了问题。来自此 post PFUser currentUser nil after app update 的 Eddy 还表示恢复到以前的 Parse SDK 也解决了这个问题。
我正在为后端使用 Parse 开发 swift iPhone 应用程序,当我重新启动应用程序时,无法识别 currentUser
并且 returns 无重定向到登录页面。一旦我重新登录,用户将保持登录状态,直到我停止该应用程序。
if PFUser.currentUser() == nil {
//return to the login page
} else {
// perform normal operations
}
我很好奇为什么会发生这种情况,因为我唯一拥有 PFUser.logOut()
的地方是在注销功能中,该功能不在初始视图控制器上,仅在按下按钮时调用。在此先感谢您的帮助!
编辑:这个问题是今天早上开始出现的。在过去的 2 周里,我没有遇到任何关于使用 parse 自动登录的问题。所以我不知道我能做些什么来引起它。从昨晚到今天早上,我更改的唯一代码是尝试通过向我的 VC 添加委托来将数据从一个视图控制器传递到 popoverViewController,但我已经删除了它们并且仍然不知所措。
我认为您应该将 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)
}
}
我最终下载了最新的 Parse SDK,它解决了问题。来自此 post PFUser currentUser nil after app update 的 Eddy 还表示恢复到以前的 Parse SDK 也解决了这个问题。