iOS怎么来实现关闭自动锁屏

时间:2020-12-09 21:51:15

怎么来设置[UIApplication sharedApplication]   idleTimerDisabled 属性来控制自动锁屏的效果

// 把设置idleTimerDisabled的代码放到applicationDidEnterBackground里还原系统设置

- (void)applicationDidEnterBackground:(UIApplication *)application {
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
}

// 把设置idleTimerDisabled的代码放到applicationDidBecomeActive里取消自动锁屏效果
- (void)applicationDidBecomeActive:(UIApplication *)application {
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}