屏幕常亮

2018-11-13  本文已影响7人  会飞的大西瓜v
//设置屏幕常亮
[UIApplication sharedApplication].idleTimerDisabled = YES;
//取消设置屏幕常亮
[UIApplication sharedApplication].idleTimerDisabled = NO;
//监听锁屏变化
[[UIApplication sharedApplication] addObserver:self forKeyPath:@"idleTimerDisabled" options:NSKeyValueObservingOptionNew context:nil];
 
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
    //    setToast(@"值改变操作");
    if (![UIApplication sharedApplication].idleTimerDisabled) {
       [UIApplication sharedApplication].idleTimerDisabled = YES;
    }
}
 
 
- (void)dealloc{
    [[UIApplication sharedApplication] removeObserver:self forKeyPath:@"idleTimerDisabled"];
    [UIApplication sharedApplication].idleTimerDisabled = NO;
}
上一篇 下一篇

猜你喜欢

热点阅读