自动注销 iPhone 应用程序
我希望制作一款 iPhone,一旦应用程序在前台或后台空闲指定的时间段后,该 iPhone 就会让用户退出会话。
我猜我应该使用 NSTimer,但我不知道从哪里开始。当应用程序位于前台时,如何判断用户何时处于空闲状态?我猜它应该是一个 UIApplicationDelegate 方法?
有什么建议吗?谢谢。
I'm looking to make an iphone that will log a user out of a session once the app has been either idle in the foreground or in the background for a specified period of time.
I'm guessing that I should use an NSTimer, but I don't know where to start it. How can I tell when a user has been idle when the app is in the foreground? I'm guessing that it should be a UIApplicationDelegate method?
Any suggestions? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想在应用程序进入后台时自动注销,请尝试查看应用程序委托方法。例如,有一个
applicationDidEnterBackground
方法,并且applicationWillTerminate
也可能有所帮助。您可以在此处实现自动注销。如果您想在应用程序在后台运行一段时间后注销,那么您需要启用应用程序在后台运行。为此,只需转到应用程序 info.plist 文件并添加一个新字段“应用程序不在后台运行”。确保它未被选中。然后在applicationDidEnterBackground
方法中添加一个NSTimer,经过一定时间就可以注销了。If you want to auto logout when the application enters background, try looking at the application delegate methods. For example, there is a
applicationDidEnterBackground
method, andapplicationWillTerminate
could also be helpful. This is where you could implement your automatic logout. If you want to logout after the application is in the background for a certain period of time, then you need to enable your application to run in the background. To do that just go to the application info.plist file and add a new field "Application does not run in background". Make sure it is UNchecked. Then in theapplicationDidEnterBackground
method add an NSTimer, and after a certain period of time you can logout.