iphoneobjective-cauto-lock

How do I close my iPhone App when the screen locks?


I'm writing an App that involves authentication on the initial screen, and allows access to sensitive data on later screens. When the iPhone is locked, either with the lock button or through auto-lock, I would like the App to close itself as a security measure. Is there a way I can do this?


Solution

  • Your UIApplicationDelegate will receive the

    – applicationWillResignActive:
    

    message when the screen locks, and

    – applicationDidBecomeActive: 
    

    when it comes back. However, it could also receive these messages in other situations (such as receiving a phone call, the user closes the app on iOS 4.0 and later) and I don't know of a way of distinguishing the reason.

    A better user experience in my opinion would be to pop up the authentication again when the app comes back. This way the user won't be confused when the phone unlocks, and the app they had running has mysteriously quit.