Reputation: 225
I have an app in Xcode which handles sensitive data. I would like to terminate the app / exit forcefully if there is inactivity for 5 mins. Can someone please tell me how to do this? Thank you!
Upvotes: 1
Views: 979
Reputation: 4737
Click here for a tutorial on how to make a timer. Every action that the user takes, reset the timer. When the 5 minutes are up, you can use exit(0)
.
However, this method of programatically closing your app is discouraged by Apple, so use it at your own discretion.
Edit: In order to stop the timer, you need to store a pointer to the timer that you create, and then call:
[pointerToTimer invalidate];
pointerToTimer = nil;
Edit 2: An alternative to using exit(0)
would be to make a almost blank screen except for some text that states:
You have been inactive for too long. Please exit and restart this application.
Make this screen appear once the timer gets to 5 minutes. Therefore, the user can't do anything on the app but look at the screen, or exit the app.
Upvotes: 1
Reputation: 31026
If you're writing an app to submit to the app store, you can't (according to the guidelines). See details in this note: http://developer.apple.com/library/ios/ipad/#qa/qa1561/_index.html
If you don't care about the store or interface guidelines, it suggests that exit() is available.
Upvotes: 0