菜鸟教程小白 发表于 2022-12-13 01:31:43

ios - 在 iOS 设备锁定时保持应用程序运行?


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

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

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

<p>这可能吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我会说不,这是不可能的。原因如下:</p>

<p><a href="http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html" rel="noreferrer noopener nofollow">docs</a>阅读:</p>

<blockquote>
<p>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 <code>UIApplicationStateInactive</code> (as opposed to <code>UIApplicationStateBackground</code>), and finally locks the screen.</p>
</blockquote>

<p>在上面的文档中需要注意的一点是,在“发生中断时该怎么办”下方稍稍往下一点,Apple 建议您停止执行某些任务。 </p>

<blockquote>
<p>In response to this change, your app should do the following in its <code>applicationWillResignActive:</code> method:</p>

<ul>
<li>Stop timers and other periodic tasks.</li>
<li>Stop any running metadata queries.</li>
<li>Do not initiate any new tasks.</li>
<li>Pause movie playback (except when playing back over AirPlay).</li>
<li>Enter into a pause state if your app is a game.</li>
<li>Throttle back OpenGL ES frame rates.</li>
<li>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.)</li>
</ul>
</blockquote>

<p>这告诉我,Apple 不希望或期望您的应用在这种状态下做很多事情,除了准备完全后台运行。</p>

<p>在相关说明中,这里有一个线程显示如何确定您是否按下了 sleep /唤醒按钮:</p>

<p> <a href="https://stackoverflow.com/questions/7754317/is-it-possible-to-distinguish-between-locking-the-device-and-sending-an-app-to-b" rel="noreferrer noopener nofollow">Is it possible to distinguish between locking the device and sending an app to background?</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在 iOS 设备锁定时保持应用程序运行?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/15305314/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/15305314/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在 iOS 设备锁定时保持应用程序运行?