views:

120

answers:

1

I am trying to disable the automated sleeping of iPhone for certain period in my app. Used [[UIApplication sharedApplication] setIdleTimerDisabled:YES] which works fine as long as I play no music.

But when I play music the Idle Timer seems to get reactivated.

I have tried all kinds of tricks from NSTimer firing silent sounds every 10 second etc but nothing works.

Would welcome any suggestion or thoughts on making this happen.

A: 

The way to fix this is to first subclass UIApplication, override the setIdleTimerDisabled method and make it do nothing. Then, add a couple of your own methods that you'll call from your application instead of using the normal setter. By doing this you will ignore all messages that might change the idle timer aside from the custom method calls you make yourself. Here's an example of the subclassed UIApplication's methods:

- (void)setIdleTimerDisabled:(BOOL)disabled
{
    // do nothing! take that stupid ipod controller!
}

- (void)enableIdleTimer
{
    [super setIdleTimerDisabled:NO];
}

- (void)disableIdleTimer
{
    [super setIdleTimerDisabled:YES];
}
tweened