IOS idleTimerDisabled behavior

There are two states in my iPhone application: user interface and game. The game is played using the tilt of the device, so I turned on the automatic sleep mode when the game started:

[[UIApplication sharedApplication].idleTimerDisabled = TRUE; 

But as soon as I get back to the user interface, again I want the automatic sleep to be active. So, at the end of the game, I restore it:

 [[UIApplication sharedApplication].idleTimerDisabled = FALSE; 

After a long game, this led to an immediate darkening of the first screen of the user interface that I go after the game. Therefore, it seems that when the inactivity timer was turned off, he was still calculating the time. And he shot right after the "turn on". How can I fix this problem?

+6
source share
2 answers

I do not know if idleTimer be reset programmatically, but the option should require the user to touch the screen before he returns.

Another option is to set your timeout after you return and wait for it to complete before setting idleTimerDisabled = NO . Remember to clear this timeout if you start the game again.

+2
source

This answer may be helpful.

I also had problems using Music / Audio players that seemed to activate the timer.

ps: in ObjectiveC you should use YES / NO instead of FALSE / TRUE

+1
source

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


All Articles