views:

230

answers:

2

For example I have a game with a menu screen and then I have the game itself. I want the timer disabled whilst playing the game but enabled when in the menu screen. I currently have the following code in my app delegate that disables the timer:

application.idleTimerDisabled = YES;

Any help would be appreciated.

+1  A: 

Just set it to NO when you show the menu. You can enable and disable the timer as you like, with the code you show.

Pascal
I was under the impression you could only use this code in the app delegate?
No, as Ed also answered, you can do this from anywhere. The code then is just `[UIApplication sharedApplication].idleTimerDisabled = YES/NO;`Generally, the app does not care where you do your stuff. It's only a matter of getting the right object (the UIApplication singleton in this case). :)
Pascal
A: 

If you can do it in your app delegate, why wouldn't you be able to do it from anywhere else? The only question is how to get a reference to application:

[Application sharedApplication].idleTimerDisabled = NO;
Ed Marty
I think you meant: [UIApplication sharedApplication].idleTimerDisabled = NO;
Carl Coryell-Martin