xcode iPhone - 如何在后台执行任务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11859011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iPhone - How to perform task in background?
提问by Rajneesh071
I want to call a method in a regular time interval when the app is running in the background(minimize).
我想在应用程序在后台运行时定期调用一个方法(最小化)。
like i want to call web service daily....and want to show the result of this webService in the localNotification message body. How to do this Task ?
就像我想每天调用 Web 服务一样......并且想在 localNotification 消息正文中显示此 WebService 的结果。如何做这个任务?
回答by Kao
Please follow this guide, provided from Apple, to see how applications enter the background:
请遵循 Apple 提供的本指南,了解应用程序如何进入后台:
Look for the section called Background Execution and Multitasking:
查找名为Background Execution and Multitasking的部分:
However, you can only run specific kind of tasks 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
If your application falls within the grasp of these types, you can now proceed to determine the application type.
The possible types are:
- audio—The app plays audible content to the user while in the background. (This content includes streaming audio or video content using AirPlay.)
- location—The app keeps users informed of their location, even while it is running in the background.
- voip—The app provides the ability for the user to make phone calls using an Internet connection.
- newsstand-content—The app is a Newsstand app that downloads and processes magazine or newspaper content in the background.
- external-accessory—The app works with a hardware accessory that needs to deliver updates on a regular schedule through the External Accessory framework.
- bluetooth-central—The app works with a Bluetooth accessory that needs to deliver updates on a regular schedule through the CoreBluetooth framework.
但是,您只能在后台运行特定类型的任务:
- 在后台向用户播放可听内容的应用程序,例如音乐播放器应用程序
- 让用户随时了解其位置的应用程序,例如导航应用程序
- 支持互联网协议语音 (VoIP) 报亭应用程序需要下载和处理新内容的应用程序
- 从外部配件接收定期更新的应用程序
如果您的应用程序属于这些类型的范围,您现在可以继续确定应用程序类型。
可能的类型是:
- 音频— 应用程序在后台向用户播放可听内容。(此内容包括使用 AirPlay 流式传输音频或视频内容。)
- 位置- 即使在后台运行,该应用程序也会让用户了解他们的位置。
- voip— 该应用程序使用户能够使用 Internet 连接拨打电话。
- newsstand-content—该应用程序是一款在后台下载和处理杂志或报纸内容的报亭应用程序。
- external-accessory— 该应用程序与需要通过外部附件框架定期提供更新的硬件附件配合使用。
- bluetooth-central—该应用程序与需要通过 CoreBluetooth 框架定期提供更新的蓝牙附件配合使用。