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?
download files using http request in background in iPhone (above iOS 4.0)
Asked Answered
Everything is possible, just use the AFNetworking library from github. It will make it very easy for you. However, it can't defeat the OS limit of 10 minutes for a long running background process. –
Allpowerful
I have same doubt for beginBackgroundTask. I need to continue retrying after 10 mins. also. –
Chamblee
Tough luck, you can't keep trying after that long. –
Allpowerful
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.
I have already send http request using nsurlrequest in didFinishLaunchingWithOptions and also implemented retry logic. But after pressing home button app did not continue downloading files. So what I need to do to keep downloading in background? –
Chamblee
beginBackgroundTaskWithExpirationHandler: method gives limited time. –
Chamblee
Yeah, I don't think you can keep going after 10 mins. –
Nuzzle
© 2022 - 2024 — McMap. All rights reserved.