tags:

views:

284

answers:

4

Hi

I am using this in my appdelegate's applicationDidFinishLaunching: method to make sure the iPhone doesn't go to sleep during the time the app is open

[application setIdleTimerDisabled:YES];

It works great on all screens but on one of the screens the iPhone goes to sleep. I could not figure out how to reproduce this and it seems to happen at random times.

Can someone please tell me how to handle this situation.

Thanks

A: 

Set this property in the application delegate's +initialize method, e.g.:

+ (void) initialize {   
    if ([self class] == [MyAppDelegate class]) {
        UIApplication* myApp = [UIApplication sharedApplication];
        myApp.idleTimerDisabled = YES;
    }
}
Alex Reynolds
A: 

I set and un-set this property throughout my app using:

[UIApplication sharedApplication].idleTimerDisabled = YES;

Setting this where you're having trouble could fix it, though it might be a bit of a band-aid solution.

Kenny Winker
http://cocoabugs.blogspot.com/2010/10/how-to-aviod-application-going-to-sleep.html
jeeva
A: 

I think the setIdleTimerDisabled doesn't exist in UIApplication class. Property searches not only set- method but also other similar named methods.

Use dot accessor is the best way to solve your problem.

KatokichiSoft
A: 

I had a similar problem, and rebooting the phone fixed it. I couldn't find a programmatic fix for it, as even timers calling the idleTimerDisabled function on a one second interval didn't fix it either.

Kyle