美文网首页
屏幕常亮

屏幕常亮

作者: 会飞的大西瓜v | 来源:发表于2018-11-13 11:29 被阅读7次
//设置屏幕常亮
[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;
}

相关文章

网友评论

      本文标题:屏幕常亮

      本文链接:https://www.haomeiwen.com/subject/zuvkfqtx.html