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!
2 Answers
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.

- 4,607
- 3
- 22
- 29
-
Will this make apple decline the app if I submit it to the app store? – Sanjyot Shah Aug 05 '12 at 19:09
-
According to [this answer](http://stackoverflow.com/a/5788836/612266), it's very possible that your app will get rejected. One second, I'll think up a better option. – Jeff Gortmaker Aug 05 '12 at 19:11
-
1I added an alternative possibility. – Jeff Gortmaker Aug 05 '12 at 19:13
-
That is a fantastic idea, after the timer expires I should load a new view with no navigation possibilities which will make the user exit and reload the app! Thanks a lot!! – Sanjyot Shah Aug 05 '12 at 19:15
-
It should ideally, let me try and get back!! – Sanjyot Shah Aug 05 '12 at 19:18
-
Some users will have a problem quitting the app completely. Better explain how to do it in your "info view". – Mundi Aug 05 '12 at 19:19
-
Yes, do you mean I should specify that user should press the "Home Button" to exit the app? – Sanjyot Shah Aug 05 '12 at 19:21
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.

- 30,888
- 4
- 42
- 57
-
Is there no way to time out the app legally? I want to submit the app to the app store. – Sanjyot Shah Aug 05 '12 at 19:05
-
1I only know what is in the Tech. Note I quoted: "Allow the user to terminate the application at their own discretion.". You can disallow any other function and explain why the app isn't working as it normally would. – Phillip Mills Aug 05 '12 at 19:42
-