ios - iPad 应用程序在锁定屏幕后变为非事件状态

标签 ios ipad background screen-lock

在我的应用程序中,我在某个时间点使用 NSOperation 在单独的线程上下载和上传数据.这两个过程大约需要。 2-3 分钟。如果应用程序保持事件状态,那么一切正常。但是,如果 iPad 屏幕被锁定(自动或手动),应用程序将变为非事件状态,下载/上传会暂停,并且当屏幕在一段时间后解锁时,进程因超时错误而失败。

我在 plist 文件中有“所需背景模式”的“应用程序播放音频”。屏幕锁定时,我是否需要为运行应用程序设置任何其他标志?

请帮助我出了什么问题。

最佳答案

当屏幕锁定时,您的应用程序将变为非事件状态。根据 "Responding to Interruptions"在 iOS 应用程序编程指南中:

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.



根据"Executing a Finite-Length Task in the Background",您可以获得额外的后台任务时间在同一指南中:

Apps that are transitioning to the background can request an extra amount of time to finish any important last-minute tasks. To request background execution time, call the beginBackgroundTaskWithExpirationHandler: method of the UIApplication class. If your app moves to the background while the task is in progress, or if your app was already in the background, this method delays the suspension of your app. This can be important if your app is performing some important task, such as writing user data to disk or downloading an important file from a network server.



您可以引用文档在后台实现一个有限长度的下载任务。

其他引用:
  • Download data in background with iOS4
  • iOS Application Background Downloading
  • 关于ios - iPad 应用程序在锁定屏幕后变为非事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10493703/

    相关文章:

    ios - 采取一定数量的步骤后通知。 swift 2.0

    ios - 从 xcode 4.2 ios 5 构建将在 ios7 下运行的应用程序

    jquery - ipad click 适用于 ipad on safari

    java - 如何删除 Netbeans java 中滚动 Pane 的背景并允许包含面板的背景可见

    css - 单击展开折叠交换背景

    iOS:开始从后台播放声音

    ios - 应用程序退出 *** 断言失败 -[UITableView _configureCellForDisplay :forIndexPath:]

    ios - 无论如何,有没有办法从 Swift 中的 socket.io 方法返回一些东西?

    ios - 无法单击选项卡栏 Controller 中的更多选项列表

    javascript - Safari iPad 1 : how to disable zoom/centering on double-tap, 但保持双指缩放