iPhone - Preventing Sleep while using applicationMusicPlayer in MPMusicPlayerController

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.


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 how you do it:

Edit your main.m file to use a custom UIApplication subclass:

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSString* appClass = @"CustomUIApplicationSubclass";
    NSString* delegateClass = nil;
    int retVal = UIApplicationMain(argc, argv, appClass, delegateClass);
    [pool release];
    return retVal;

Then define your UIApplication subclass:

@interface CustomUIApplicationSubclass : UIApplication {


- (void)disableIdleTimer;
- (void)enableIdleTimer;


@implementation CustomUIApplicationSubclass

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

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

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


This will force the iPod controller to use your custom UIApplication instance which does no longer does anything when the normal setIdleTimerDisabled method is called.

Need Your Help

Tablesorter - custom parser dependent on sorting type

javascript jquery parsing sorting tablesorter

Is it possible to check inside format function which was used: ASC or DESC sorting? I want to change number format in sorting when column is sorted DESC.

How to create a timer "count up" using jQuery Countdown plugin?

javascript jquery plugins countdown

i am trying to use the jQuery plugin countdown 2.1 to count the time up. I need to clock to start at 0 and count up one second at a time.