iphone - 通过避免应用程序 10 分钟时间限制在后台连续工作

标签 iphone ios ipad service ios6

我想创建一种服务类型的应用程序,它在后台运行,但问题是 iOS 应用程序有 10 分钟的限制。

有什么方法可以让我们持续运行我们的应用程序,我读过一些内容,如果我们在后台播放一首歌曲,那么该应用程序在 10 分钟后永远不会终止,但我认为苹果不会批准这一点。

任何建议都会有所帮助。

最佳答案

来自 iOS 开发者库:

iOS 7 supports two new background execution modes for apps:

Apps that regularly require new content can register with the system and be woken up or launched periodically to download that content in the background. To register, include the UIBackgroundModes key with the fetch value in your app’s Info.plist file, and set the minimum time you want between fetch operations using the setMinimumBackgroundFetchInterval: method. You must also implement the application:performFetchWithCompletionHandler: method in your app delegate to perform any downloads. Apps that use push notifications to notify the user that new content is available can now use those notifications to initiate background download operations. To support this mode, include the UIBackgroundModes key with the remote-notification value in your app’s Info.plist file. Your app delegate must also implement the application:didReceiveRemoteNotification:fetchCompletionHandler: method.

第一种情况: 通过将 setMinimumBackgroundFetchInterval: 设置为 UIApplicationBackgroundFetchIntervalMinimum 或任何其他秒数(在您的 AppDelegate 内)将通知系统您的应用需要更新其内容,即使它在后台也是如此.

请注意。获取间隔是最小值而不是最大值!因此,您的应用程序将在系统决定时唤醒。这可能是一天一次或一天多次。就我而言,我的应用正在更新大约。每 10 分钟一类,直到 19:00。在那之后,花了大约。下一次更新 7 小时,下一次更新 3 小时。第二天,相同(每 10 分钟一类,直到 19:00)。

如果您要求从 Internet 定期更新(高效且低电池消耗),则此技术是理想的选择,但不适用于需要在短时间内更新的内容,例如电池电量或电池状态。

希望这对您有所帮助。

iOS 7 仍处于测试版。因此,在正式发布之前,上述所有内容都可能会更改或更新。

关于iphone - 通过避免应用程序 10 分钟时间限制在后台连续工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18631524/

相关文章:

ios - UITabBarController 不显示其他选项卡的标题

iphone - Google AdMob 不显示广告

ios - 如何使用 UIBezierPath 绘制带有动画的扇形?

从 Obj-C 类继承的 Swift 中的 iOS 错误转换对象

iphone - 添加到 NSDictionary 条目到 NSMutableDictionary

objective-c - 如何设置uiclearcolor的alpha?

iphone - 长按添加新 View 后如何保留触摸事件

iphone - 适用于 iOS 应用程序的分析库

iphone - 来自 iphone/ipad 应用程序的 RewriteCond

iphone - 在 "viewDidLoad"方法期间发出的 UIActionSheet 提示是否应该暂停方法中的代码,直到它被用户操作?