4

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 .

Carina
  • 2,260
  • 2
  • 20
  • 45

2 Answers2

1

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.

Community
  • 1
  • 1
borrrden
  • 33,256
  • 8
  • 74
  • 109
  • 1
    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 06: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 06:31
0

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.

jad4
  • 1
  • 1
    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 03: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 03:42