维护 iPhone 应用程序中的会话状态
您好,我想在我的 iPhone 应用程序中维持会话。如果应用程序进入后台状态或应用程序未激活,我必须将用户移至登录屏幕。这个要怎么做呢?
我看到了这个例子,但它并不能帮助我解决问题:
HI, I want to maintain the session in my iphone application. If the application enter in to background state or application is not active i have to move the user to loging screen. How to do this one?
I saw this example but it is not help me to resolve the issue:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以遵循类似的概念。当用户登录时,将一些内容设置为 NSUserDefaults,例如
[[NSUserDefaults standardUserDefaults] setValue:@"ABCDEFGHIJK" forKey:@"SessionKey"];
并且在应用程序委托中有一种名为
(void ) applicationDidEnterBackground:(UIApplication *)application
当应用程序进入后台时将被调用。只需删除会话密钥的设置变量即可。当应用程序再次启动时,只需检查条件并将用户重定向到所需的屏幕。
希望这有帮助。
You can follow similar concept. When user logging in put some thing as NSUserDefaults like
[[NSUserDefaults standardUserDefaults] setValue:@"ABCDEFGHIJK" forKey:@"SessionKey"];
and in application delegate there is one method called
(void) applicationDidEnterBackground:(UIApplication *)application
which will be called when application is going in background. Just remove that set variable for the sessionkey. And while application is again being launched just check the condition and redirect user to desired screen.
Hope this helps.