3

I'm using

[[UIApplication sharedApplication] setIdleTimerDisabled: YES];

to keep the app from entering idle, however when I issue

[[UIApplication sharedApplication] setIdleTimerDisabled: NO];

the app goes straight to idle.

Is there a way to restart the timer at this point?

robspencer77
  • 149
  • 2
  • 11

2 Answers2

1

No there is no way to restart the timer. Perhaps you should consider if your app really needs to do this. Quote from Apple:

"The only applications that should disable the idle timer are mapping applications, games, or similar programs with sporadic user interaction."

If you app does need to turn the idleTimer off then perhaps it can stay off till the app goes in to the background?

You could try adding an alert at the end of the timed event

UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Timer Complete" message:@"Timer ended, well don you" delegate:nil cancelButtonTitle:@"OKAY" otherButtonTitles:nil];
[myAlert show];
[myAlert release];

Omit the release if you're using ARC. This may light the screen backup, then perhaps you don't need to mess with the idle timer.

AppHandwerker
  • 1,758
  • 12
  • 22
  • The app is basically a phased countdown to be used during training, with audio alerts for the phases, so there's is sporadic (no) user interaction for just over 5 minutes. I guess the question is whether it's possible to simulate user interaction at the point where the timer ends. – robspencer77 Aug 04 '12 at 12:19
  • I don't think so, but perhaps when the timer ends you could show and alert – AppHandwerker Aug 06 '12 at 20:47
0

This is obviously too late for the person who asked this question, but for anyone else who is looking, what has worked for me is to do this:

[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];

Including all three lines one after the other somehow resets the timer. So the timer won't dim upon immediately receiving setIdleTimerDisabled:NO but rather will take a while before it dims.

Sergio Prado
  • 1,197
  • 2
  • 16
  • 33