开发者

How do I keep the user's iPhone's display on?

开发者 https://www.devze.com 2023-04-11 20:44 出处:网络
So, I was looking for a way to keep the user\'s iPhone display on for a clock app. I found [UIApplication sharedApplication].idleTimerDisabled = YES; but that keeps the device from locking all of the

So, I was looking for a way to keep the user's iPhone display on for a clock app. I found [UIApplication sharedApplication].idleTimerDisabled = YES; but that keeps the device from locking all of the time. I tried t开发者_如何学JAVAo [UIApplication sharedApplication].idleTimerDisabled = NO; when the application goes into the background, but that doesn't work. How can I safely keep the user's device from sleeping while my app is running?


Alter the idleTimerDisabled property whenever your app changes its active state - if you're going to be backgrounded, re-enable the timer, and when you regain control, disable the timer again.


Here's my solution, using XCode 6.2.

iPhone - phone goes to sleep even if idleTimerDisabled is YES

Basically, even now, in 2015, the only way to safely make sure that the device doesn't go to sleep is to repeatedly call a piece of code to keep the device awake.

-(void)callEveryTwentySeconds
{
    //  DON'T let the device go to sleep during our sync
    [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消