长时间运行的任务在后台

时间:2011-12-10 15:27:19

标签: background ios5

我创建了一个应用程序,每7分钟从服务器下载并解析xml数据。

我希望它在大部分时间都可以在后面运行,所以如果有任何更改,这个应用程序可以发送本地通知。

我阅读了Apple对长期运行后台任务的要求,并且没有合适的类别:

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:

Apps that play audible content to the user while in the background, such as a music player app
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Newsstand apps that need to download and process new content
Apps that receive regular updates from external accessories

有任何建议吗?

1 个答案:

答案 0 :(得分:1)

创建一个NSThread,而不是让睡眠无限循环,你最好使用NSTimer。您可以使用timerWithTimeInterval:invocation:repeats:初始化它,然后在运行循环中安排它的后台线程。