【问题标题】:idleTimerDisabled not working with (Autonomous) Single App ModeidleTimerDisabled 不适用于(自治)单应用程序模式
【发布时间】:2020-11-24 01:23:21
【问题描述】:

我们有一个自助服务终端应用程序,我们在其中使用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;
}

在我们开始使用自主单一应用模式之前,它一直运行良好。现在屏幕不再在晚上关闭。对此有解释(和解决方法)吗?我知道 iOS 12 中存在一个错误,其中idleTimerDisabled 不再适用于引导访问,但我还没有看到关于单应用模式类似问题的报告。

【问题讨论】:

  • 我实际上遇到了同样的问题。你找到解决方案了吗?
  • 不幸的是还没有。我怀疑这是一个类似于 idleTimerDisabled 和引导访问的错误。
  • 只是给你一些额外的信息。如果我拿起它并导致方向改变,我实际上可以让睡眠定时器工作......这对于信息亭应用程序仍然没用。

标签: ios ios12


【解决方案1】:

触发本机操作可能会“解决”问题。我能够使用下面的代码解决我的问题。

尝试使用以下代码:

    [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];

【讨论】:

  • 非常感谢,这就像一个魅力!在我们的测试中,将设备插入充电器也会将设备(很可能是 SpringBoard)从这种“锁定”状态中拉出来,但这似乎也可以可靠地解决它。现在……
【解决方案2】:

我们的方法是重置空闲计时器,它不会通过重置 idleTimerDisabled 来禁用:

Timer.scheduledTimer(withTimeInterval: 840, repeats: true, block: { timer in
       DispatchQueue.main.async {
             UIApplication.shared.isIdleTimerDisabled = false
             UIApplication.shared.isIdleTimerDisabled = true
       }
 })

这也有效。

【讨论】:

    猜你喜欢
    • 2015-11-30
    • 2014-06-21
    • 2014-05-03
    • 1970-01-01
    • 2014-06-16
    • 2013-07-17
    • 2013-01-23
    • 2020-04-22
    • 1970-01-01
    相关资源
    最近更新 更多