Take the 2-minute tour ×

I added UIApplicationExitsOnSuspend to my Info.plist and set it to YES. The key completely exit my app when the home button is tapped. But how about screen-lock ? or how can I detect screen lock event? There is no key named UIApplicationExitsOnScreenLock I want .

share|improve this question
I'd be pretty surprised if locking my phone killed the running application. Are you confident you want to do this? –  sarnold Jul 17 '12 at 2:20
Alternatively you could call for user login in a method triggered in viewDidAppear. –  0x7fffffff Jul 17 '12 at 3:19

2 Answers 2

up vote 1 down vote accepted

See the clever workaround in this answer. This seems to be the only way to do it but it is a hack, so changes to iOS could make it not work.

share|improve this answer
Thank you for your reply.You mean they might reject my app ? If I do not care about it,I will add exit(EXIT_SUCCESS); to applicationWillResignActive: callbacks. –  Carina Jul 17 '12 at 6:17
No, it is perfectly valid but it depends on the assumption that the accelerometer is not available during lock. If they make it available in future revisions of iOS for whatever reason, this hack will not work anymore. –  borrrden Jul 17 '12 at 6:31

Quitting like that is not really appropriate. In your app delegate's -applicationWillResignActive:, just unauthenticate the user, or whatever it is you are trying to accomplish with a full re-start each time. I don't know what steel safe is, but it probably does not quit like that.

Or maybe check for the UIApplicationProtectedDataWillBecomeUnavailable notification? However, it's only sent on device lock if the user has a passcode enabled. If you use NSFileProtectionComplete on your "secret" files, close them when going inactive.

share|improve this answer
Be careful though, double clicking the home button will also cause the application to resign active (though all it does it pop up the bottom bar), but I don't think the user will want to be logged out. –  borrrden Jul 17 '12 at 3:38
Yes, I should have mentioned that. Also pulling down the notification center, getting a phone call or facetime invite, etc. But, you will definitely be able to see that you are in inactive state, versus not getting UIApplicationProtectedDataWillBecomeUnavailable because the user hasn't set a passcode. –  jad4 Jul 17 '12 at 3:42

Your Answer


