//设置屏幕常亮
[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;
}