ios - 检查用户是否有效 Parse (Swift)

标签 ios swift authentication parse-platform

我现在的问题是,如果数据库中的用户发生某些变化(在测试期间手动更改),则不会更新客户端缓存的用户。我知道我需要使用 fetch() 或其中一种变体(背景,如果需要的话),但我真的不知道该怎么做。

这是我在 AppDelegate 中的当前代码,用于确定是显示登录屏幕还是继续到主应用程序。

        // Decide which controller to go to
        self.window = UIWindow.init(frame: UIScreen.main.bounds)

        var sb: UIStoryboard? = nil
        if (PFUser.current() != nil) && (PFUser.current()?.isAuthenticated)! {
            sb = UIStoryboard(name: "Main", bundle: nil)
        } else {
            sb = UIStoryboard(name: "SetupUser", bundle: nil)
        }

        let vc = sb?.instantiateInitialViewController()
        self.window?.rootViewController = vc
        self.window?.makeKeyAndVisible()

这在大多数情况下都有效,但如果用户从数据库中更新或删除,应用程序将继续运行并稍后因更新/保存对象错误而崩溃。

最佳答案

我建议使用带有完成 block 的fetchInBackground

 PFUser.current()?.fetchInBackground(block : { (user, error) in
          if let user = user {
             //show Main
          }else {
             //showLogin
           }

    })

通过这种方式,您可以在获取用户后执行您的逻辑。

关于ios - 检查用户是否有效 Parse (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43528111/

相关文章:

ios - 什么是 -applicationDidFinishLaunching 和 -applicationWillFinishLaunch?

ios - React native - ios 中的 rtl

asp.net - 为什么 HttpContext.Current.User.Identity.Name 返回空白

ios - Swift:无法在 TableViewController ( Storyboard)上创建按钮操作

ios - 使用带有多个参数的@objc 委托(delegate)方法

javascript - 如何在 swift 中从 .js 文件调用 javascript 函数

ios - Swift 中创建子类对象的类函数

ios - CAGradientLayer 在像素处获取颜色

java - 用户登录时启用页面上的按钮/GWT

c# - WebMatrix razor C# WebSecurity 登录但 Web.Security.IsAuthenticated 未返回正确的检查