1

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!

Sanjyot Shah
  • 225
  • 1
  • 5
  • 17

2 Answers2

1

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.

Jeff Gortmaker
  • 4,607
  • 3
  • 22
  • 29
0

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.

Phillip Mills
  • 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
  • 1
    I 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
  • Yes, that is what I exactly did. Thanks Phillip!! – Sanjyot Shah Aug 05 '12 at 22:19