I have an iPad app where the user can set the idleTimerDisabled to YES or NO via a switch in preferences. That part works fine. However, initially setting it to YES in the app delegate's didFinishLaunchingWithOptions method if it's the first time the app has run doesn't work (the device auto-sleeps anyway).
I've tried the hack of setting it to NO first, then to YES, as described in other threads to no avail. All other aspects of the preferences (standardUserDefaults) are working fine, as well.
Here's the relevant code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// if app run for the first time, set these as defaults
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if (![prefs objectForKey:@"autoSleep"]) {
// this conditional code runs, as traced using NSLog
[prefs setBool:YES forKey:@"autoSleep"];
application.idleTimerDisabled = NO;
application.idleTimerDisabled = YES;
}
}