我们有一个信息亭应用程序,我们在其中使用 idleTimerDisabled
来防止屏幕在工作时间关闭,并让它在晚上关闭。
我使用在 applicationDidBecomeActive
方法中创建的计时器执行此操作:
self.screenLockTimer = [NSTimer scheduledTimerWithTimeInterval:300 target:self selector:@selector(setupScreenLock) userInfo:nil repeats:YES];
-
- (void)setupScreenLock {
NSDate *currentDate = [NSDate date];
NSDate *closingDate = [[NSCalendar currentCalendar] dateBySettingHour:17 minute:0 second:0 ofDate:currentDate options:0];
BOOL isOpeningHours = [currentDate compare:closingDate] == NSOrderedAscending;
[UIApplication sharedApplication].idleTimerDisabled = isOpeningHours;
}
在我们开始使用Autonomous Single App Mode 之前,这曾经工作得很好。现在屏幕不再在晚上关闭。对此有解释(和解决方法)吗?我知道 iOS 12 中存在一个错误,其中 idleTimerDisabled
不再适用于引导访问,但我还没有看到关于单一应用模式的类似问题的报告。
最佳答案
触发 native 操作可能会“解决”问题。我能够使用下面的代码解决我的问题。
尝试使用以下代码:
[UIApplication sharedApplication].idleTimerDisabled = isOpeningHours;
// Guided access idle timer fix
UITextField *textField = [[UITextField alloc] init];
[self.view addSubview:textField]; // self.view or whatever relevant view is accessible.
[textField becomeFirstResponder];
[textField resignFirstResponder];
[textField removeFromSuperView];
关于ios - idleTimerDisabled 不适用于(自主)单一应用程序模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55813336/