theDuncs
theDuncs

Reputation: 4843

Long-running task performed in foreground is suspended when app enters background

When a user first opens my app, I need to download and install some content from a server before they can begin using the app. The problem is that this takes around 5 minutes on wifi, during which time the app goes into the background and the download is suspended.

Is there any way to either:

Thanks

Upvotes: 1

Views: 1267

Answers (3)

Fahri Azimov
Fahri Azimov

Reputation: 11770

You can't do what you want, in this situation. One way, and I think the best and only, is to resume your download when you app becomes active (returns to foreground state). Also, don't forget to register for connectivity notifications (Reachability class can be used for this purpose from this Apple sample app http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html). Good Luck!

Upvotes: 0

jrturton
jrturton

Reputation: 119242

Can't you include some or all of the content in your app bundle instead, and just download changes on first run?

I can't imagine this is a good first user experience, and it may not pass App Store review like this.

The only third party apps that are allowed to download in the background are newsstand apps loading issue content, and Apple are pretty strict about what they allow as newsstand apps.

Upvotes: 0

Rui Peres
Rui Peres

Reputation: 25907

It really doesn't matter, if the user presses the home button it will go to background. Although you can do two things to mitigate the problem:

  • Use beginBackgroundTaskWithExpirationHandler, to give you a bit more time to download. Which you can read here.
  • Don't allow the device to become iddle, with [UIApplication sharedApplication].idleTimerDisabled = YES;. You can read more about that here.

Either way, the best thing you can do is to tell the user, that is an important download and he shouldn't quit the application.

Upvotes: 3

Related Questions