4

我有一个大量使用视频输出的应用程序。在一个典型的用例中,我将 iPad 连接到外接显示器。我只想打开外接显示器;iPad 显示屏不需要一直亮着。

理想的情况是让某人连接到外接显示器,然后锁定他们的 iPad。但这会暂停我的应用程序。(目前,我正在调用 setIdleTimerDisabled 以防止 iPad 锁定和暂停我的应用程序。)

我想为用户提供锁定 iPad 的选项,但仍让我的应用程序运行并将图像发送到视频。(注意:我不是说在我的应用程序不在前台时保持运行。我只想在前台保持运行,但设备被锁定。)

这可能吗?

4

1 回答 1

4

I would say no, it is not possible. Here's why:

The docs read:

Pressing the Sleep/Wake button is another type of interruption that causes your app to be deactivated temporarily. When the user presses this button, the system disables touch events, moves the app to the background but sets the value of the app’s applicationState property to UIApplicationStateInactive (as opposed to UIApplicationStateBackground), and finally locks the screen.

Something interesting to note in the docs above is that a bit further down under "What to do when an interruption occurs" Apple recommends that you stop doing certain tasks.

In response to this change, your app should do the following in its applicationWillResignActive: method:

  • Stop timers and other periodic tasks.
  • Stop any running metadata queries.
  • Do not initiate any new tasks.
  • Pause movie playback (except when playing back over AirPlay).
  • Enter into a pause state if your app is a game.
  • Throttle back OpenGL ES frame rates.
  • Suspend any dispatch queues or operation queues executing non-critical code. (You can continue processing network requests and other time-sensitive background tasks while inactive.)

This tells me that Apple doesn't want or expect your app to be doing much of anything in this state, other than preparing to be fully backgrounded.

On a related note here's a thread that shows how to determine whether you've hit the Sleep/Wake button or not:

Is it possible to distinguish between locking the device and sending an app to background?

于 2013-03-09T01:14:08.357 回答