问题
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