download files using http request in background in iPhone (above iOS 4.0)

无人久伴 提交于 2019-12-11 17:58:31

问题


I am new to iOS. I want to know some basic need for my application is possible or not? "When my application starts (tapping on my application icon), app should download some 5-10 files from server. It should continue its downloading in background also if "Home" button is pressed. And my app has retry logic i.e. if server is unreachable and request timeout occurred then app will wait for some time and send request again and again till downloading completed." Is it possible?


回答1:


So what you should do is either in the app delegate didFinishLaunchingWithOptions:, you ask it to make an nsurlrequest (or something similar from an open source framework). Also, it isn't hard to code retry logic yourself. A common method is exponential backoff, meaning that you wait 2, 4, 8, 16, etc. milliseconds, and then at some point you display a UIalertview if it looks like the server is really down for a while (if you hit a certain backoff, stop trying).

For dealing with the application when it enters the background, that's also in the app delegate.



来源:https://stackoverflow.com/questions/14828955/download-files-using-http-request-in-background-in-iphone-above-ios-4-0

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