IOS: how do you prevent the screen from being highlighted immediately after re-enabling idleTimer

I am working on an iOS game that mainly uses the accelerometer input. Previous programmers set idleTimerDisabled = YES at startup and left it that way. I recently made such a change that the idle timer is disabled only during game play and turns on again when the level ends.

The problem is that if the playback time of the level is longer than that of the idleTimer user, the screen will be gray at the moment I set idleTimerDisabled = NO. Is there a way to reset the timer when I turn it back on, so that a full time increment will happen before idleTimer reduces the screen?

+6
source share
1 answer

Disable the timer idle timer using something like this.

[self performSelector:@selector(enableIdleTimer) withObject:nil afterDelay:4]; - (void)enableIdleTimer { [[UIApplication sharedApplication] setIdleTimerDisabled:NO]; } 

Alternatively, this is a more modern and simple approach:

 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[UIApplication sharedApplication] setIdleTimerDisabled:NO]; }); 
+7
source

Source: https://habr.com/ru/post/899728/


All Articles