[英]Swift: How to check in AppDelegate if user is already logged in
My login with Deployd and Alamofire is working completely fine. 我在Deployed and Alamofire上的登录完全正常。 Here is the code:
这是代码:
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!")
}
}
How can I check in the AppDelegate
if the user is already logged in? 如果用户已经登录,我如何签入
AppDelegate
? I am using the Deployd API on a custom server for user authentication and would like to hide the 'Login Screen' ( LoginViewController
) if the user is already logged in and has an active session. 我正在使用自定义服务器上的Deployed API进行用户身份验证,并且如果用户已经登录并具有活动会话,则想隐藏“登录屏幕”(
LoginViewController
)。
Just check if access_token
exists, like in FB API. 只需检查
access_token
存在,就像在FB API中一样。 Or you can hold it in NSUserDefaults
if you logged successfully: 或者,如果您成功登录,则可以将其保存在
NSUserDefaults
:
if currentAccessToken != nil {
print("User logged in")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.