iPhone sdk, Running app in background and send frequent http request

走远了吗. 提交于 2020-01-01 19:30:13

问题


I am trying to take advantage of iPhone 4 multitasking feature. I want to run app in background and frequently send http request to send/receive data, is it possible?


回答1:


Surprisingly, there is actually very little time-slicing going on in the "multi-tasking" iOS 4.x. What goes on instead is really just application suspend / resume. When an application is sent to the background upon the user tapping the home button, it will stop getting execute cycles after a short while (*).

(*) There are a few exceptions. Applications which declare themselves as "VoIP providers", location-based apps, and music apps can get background execute cycles, presumably only though to perform those very specific operations in response to corresponding events (like a "significant change in location" occurring). Some apps apparently try to stretch the rules and find undocumented or not-strongly-documented techniques to continue getting background execute cycles.

And the "requested running time" that Undeadlegion mentioned is limited in duration.

The reality is that on iOS4, applications are not allowed to run continuously in the background.




回答2:


@Undeadlegion has suggested a plausible way to achieve your goal. To be more clear, take a look at my previous answer to a similar question at SO, iphone - Connecting to server in background




回答3:


It is possible to request running time while your app is backgrounded.

See Multitasking Developer's Guide

Although, depending on the intent of your http requests, push notifications may be a viable alternative.

This may be necessary because you aren't providing audio, voip, or location services, so your app can't run in the background indefinitely.



来源:https://stackoverflow.com/questions/4954661/iphone-sdk-running-app-in-background-and-send-frequent-http-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!