My app supports pin code for my users and I was asked to show the pin code every time the app returns from multitasking or the device returns from sleep.
In order to make sure the first thing the user sees is the pin code screen and not the real data for a sec before seeing the pin code, I am watching the applicationDidEnterBackground and applicationWillResignActive methods.
The problem is that applicationWillResignActive is called on many occasions like when the user is double tapping on the home button, gets an SMS or push notification, on tries to purchase an in app purchase request.
Is there a way for me to separate all of those cases and simply recognize the auto sleep of the device or the case when the user taps on the sleep button?
Thanks
Roi
There isn’t a direct way to differentiate all the reasons why your app enters the background mode. You can, however, call
CFAbsoluteTimeGetCurrent()inapplicationWillResignActive:, save the time stamp, and check if enough time has passed inapplicationDidBecomeActive:to warrant showing PIN code entry. For example, if less than 10 seconds has passed, you can skip showing PIN code entry. This does make your app less secure, but then it will nag users a bit less too.While this solution may look far from being ideal, in fact, it doesn’t matter why your app resigned its active state. Whatever the reason, it may become active after a very long time, and it may as well never become active again if iOS decides to terminate it.