【问题标题】:PFUser currentUser returns nil after restarting appPFUser currentUser 重启应用后返回 nil
【发布时间】:2015-09-06 16:50:01
【问题描述】:

我正在开发一个使用 Parse 作为后端的快速 iPhone 应用程序,当我重新启动应用程序时,currentUser 无法识别并返回 nil 重定向到登录页面。一旦我重新登录,用户就会保持登录状态,直到我停止应用程序。

if PFUser.currentUser() == nil {
  //return to the login page 
} else {
  // perform normal operations
}

我很好奇为什么会发生这种情况,因为我拥有PFUser.logOut() 的唯一位置是注销功能,它不在初始视图控制器上,并且仅在按下按钮时调用。提前感谢您的帮助!

编辑:这个问题从今天早上开始出现。在过去的两周里,我没有遇到任何关于使用解析自动登录的问题。所以我不知道我能做些什么来导致它。我昨晚和今天早上之间更改的唯一代码是尝试通过将委托添加到我的 VC 来将数据从一个视图控制器传递到 popoverViewController,但我已经删除了它们并且仍然不知所措。

【问题讨论】:

  • 重启应用是什么意思?
  • 你使用 Parse 本地数据存储吗?
  • 通过重新启动应用程序,我的意思是杀死它和所有后台进程,然后重新打开它。不,我没有将本地数据存储用于任何事情。
  • 我没有使用本地数据存储,但它已启用
  • 听起来你没有在登录时设置 currentUser。

标签: ios swift parse-platform swift2 pfuser


【解决方案1】:

我最终下载了最新的 Parse SDK,它解决了这个问题。来自这篇帖子PFUser currentUser nil after app update 的 Eddy 还说恢复到以前的 Parse SDK 也解决了这个问题。

【讨论】:

    【解决方案2】:

    我认为您应该将此代码放在 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)
    
        }
    
    }
    

    【讨论】:

    • 它仍然为用户返回 nil 并跳转到登录表单页面
    • 您在关闭应用之前登录了吗?
    • 是的,我尝试了两个不同的帐户,结果却是相同的
    • 你的 PFUser.Logout() 怎么样?你也应该尝试重置你的模拟器,因为这很奇怪
    • PFUser.logOut() 完美运行。刚刚重启了我的手机和模拟器,我们看看会发生什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    相关资源
    最近更新 更多