如何维护iPhone的会话 [英] How to maintain Session for iphone
问题描述
在我的Iphone应用程序中,用户使用用户名和密码登录.用户登录后,他可以通过API访问每个属性和功能.但是我想保持一个会话.也就是说,如果用户在应用程序中什么也不做,则在30分钟后,会话应终止,并且必须要求用户使用其用户名和密码登录.
In my Iphone App, User logins with Username and password. At after user logged in, He can access every attribute, features through APIs. But i want to maintain a session. That is, If user doing nothing in app, After getting 30 mins, Session should expire and user must be asked to login with his Username and password.
推荐答案
我目前正在研究完全相同的东西.
I am currently working on something exactly the same.
我为会话有效性执行以下方案:
I do the following scenario for the session validity:
-
如果
Session令牌
似乎无效,则在第一个传入请求中,我尝试在后台静默再次重新生成会话密钥.
By the first incoming request if the
Session Token
appeared to be invalid I try to re-generate the session key again silently in the background.
如果由于某些原因(例如,用户从其他地方更改了密码),步骤1无法正常工作,我将用户再次重定向至登录页面,并且出现类似您的会话密钥已过期,请登录"的提示再次进入".
If procedure #1 did not work for some reasons such as the user changed his password from somewhere else I redirect the user to the log in page again and I alert something like "Your session key has been expired please log in again".
要获得更多信息,我将会话密钥存储在 NSUserDefaults
中:
To get more into this I store the Session key in the NSUserDefaults
:
// Saving the Key
[[NSUserDefaults standardUserDefaults] setValue:@"ABCDEFGHIJK" forKey:@"SessionKey"];
// Reading the Key
[[NSUserDefaults standardUserDefaults] stringForKey:@"SessionKey"];
希望这会有所帮助.
这篇关于如何维护iPhone的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!