Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS idleTimerDisabled behavior

Tags:

ios

iphone

timer

My iPhone application has two states: UI and Game. Game is played using device tilting only so I switched auto-sleep off on game start:

[[UIApplication sharedApplication].idleTimerDisabled = TRUE;

But as soon as I return to UI, I want auto-sleep to be active again. So on game finish I restore it:

[[UIApplication sharedApplication].idleTimerDisabled = FALSE;

After a long game playing, it resulted in immediate darkening of the first UI screen that I go after the game. So it seems that when idle timer was disabled it was still calculating time. And it had fired immediately after "enabling". How can I fix this problem?

like image 973
Nick Avatar asked Nov 17 '11 16:11

Nick


2 Answers

I don't know if the idleTimer can be reset programmatically, but an option is to require the user to touch the screen before it goes back.

Another option is set your own timeout once you are back and wait for it to complete before you set idleTimerDisabled = NO. Remember to clear this timeout if you start the game again.

like image 173
Gil Avatar answered Oct 22 '22 08:10

Gil


This answer may be usefull.

I also had problems when using Music/Audio players, which seemed to reactivate the timer.

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

like image 44
Daniel Avatar answered Oct 22 '22 07:10

Daniel