ios - Swift:如果用户已经登录,如何 checkin AppDelegate

标签 ios swift deployd

我使用 Deployd 和 Alamofire 的登录完全正常。这是代码:

    let credential = NSURLCredential(user: "username", password: "password", persistence: .ForSession)
    let parameters = ["username" : "username", "password" : "password"]
    Alamofire.request(.POST, "http://xxxxxxxxxxxx/users/login", parameters: parameters)
        .authenticate(usingCredential: credential)
        .response { request, response, _, error in
            if response!.statusCode == 200 {
                self.performSegueWithIdentifier("loggedIn", sender: self)
            } else {
                print("invalid credential bro!")
        }
    }

如果用户已经登录,我如何检查 AppDelegate?我在自定义服务器上使用 Deployd API 进行用户身份验证,如果用户已经登录并且有事件 session ,我想隐藏“登录屏幕”(LoginViewController)。

最佳答案

只需检查 access_token 是否存在,就像在 FB API 中一样。或者,如果登录成功,您可以将其保存在 NSUserDefaults 中:

if currentAccessToken != nil {
    print("User logged in")
}

关于ios - Swift:如果用户已经登录,如何 checkin AppDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34724489/

相关文章:

ios - GameCenter 多人游戏卡在 "Starting Game..."

ios - Alamofire 上的事件监听器

ios - 如何在iOS 8中将小部件与NSNotificationCenter一起使用

iOS Monotouch UIImagePickerController 来自相机的多张照片/视频

ios - 更改部分页脚的宽度不起作用

android - 如何从已部署的数据中检索数据以在 Android 应用程序中使用?

node.js - Node 和/或npm问题

ios - UITabBarController 的 viewControllers 存在模态 Controller 问题

ios - 如何在 Swift 3 中正确放置背景音乐?

ios - 如何在 Xcode 8.1 中修复此错误(返回 host_statistics)?我想知道设备的可用内存