【问题标题】:Can I force the app to stay on foreground all the time?我可以强制应用程序一直停留在前台吗?
【发布时间】:2021-07-09 19:46:50
【问题描述】:

我的意思是让应用程序在没有人触摸 iPhone 时保持在前台?我需要该应用程序保持可用以接收远程命令以打开相机。希望调暗屏幕,但防止 iPhone 锁定并将应用程序置于后台?该设备可能会与充电器保持连接。

【问题讨论】:

  • 您无法以编程方式执行此操作,但您可以通过 MDM 策略(如果它是专用设备)或通过引导访问来使用单一应用模式。

标签: ios iphone


【解决方案1】:

你可以像这样尝试UIApplication.isIdleTimerDisabled

此属性的默认值为 false。当大多数应用程序在短时间内没有用户输入时,系统会将设备置于屏幕变暗的“睡眠”状态。这样做是为了节省电量。但是,没有用户输入的应用程序除了加速度计——例如游戏——可以通过将此属性设置为 true 来禁用“空闲计时器”以防止系统休眠。

// This will prevent the app from going to background (automatically by screen dimming etc.)
UIApplication.shared.isIdleTimerDisabled = true

// Do not forget to reset this after your task is done
UIApplication.shared.isIdleTimerDisabled = false

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    • 1970-01-01
    • 2013-05-21
    • 1970-01-01
    • 2011-11-23
    相关资源
    最近更新 更多