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

前端 未结 2 907
难免孤独
难免孤独 2021-01-06 04:59

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 k

2条回答
  •  我在风中等你
    2021-01-06 05:49

    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];
    }
    

提交回复
热议问题