Separating iPhone sleep from all other applicationWillResignActive scripts

My application supports a pin code for my users, and I was asked to show a pin code each time the application returns from multitasking or the device returns from sleep. To make sure that the first thing the user sees is the pin code screen, and not the real data for a second, before I see the pin code, I observe the applicationDidEnterBackground and applicationWillResignActive methods. The problem is that applicationWillResignActive is called in many cases, for example, when a user double-clicks the home button, receives an SMS message or a push notification when trying to acquire a request to purchase an application. Is there a way to separate all of these cases and simply recognize the device’s automatic sleep mode or when the user presses the sleep button?

thank

Rua

+3
source share
1 answer

There is no direct way to distinguish between all the reasons why your application goes into the background. You can, however, call CFAbsoluteTimeGetCurrent()in applicationWillResignActive:, save the time stamp and check if enough time has passed in applicationDidBecomeActive:to guarantee that the PIN code is written. For example, if less than 10 seconds have passed, you can skip the PIN code. This makes your application less secure, but then it will bore users a bit.

Although this solution may seem far from ideal, in fact, it does not matter why your application abandoned its active state. Whatever the reason, it can become active after a very long time, and it cannot be activated again if iOS decides to stop it.

+1
source

Source: https://habr.com/ru/post/1788786/


All Articles