When my app is initially downloaded, the user needs to download a large file something like 200MB (upper limit). I definitely can't expect the user to keep the app open till this file is downloaded. So he/she might close the app & the app will go into background.
How can I continue to download the file in this scenario? Is this even possible in iOS?
iOS will not allow an app to run in the background unless the developer has coded specifically to request the operating system to allow it. Without the developer writing code to keep the app "alive" and downloading, there's nothing you can do.
How to turn off Background App Refresh on your iPhone and iPad. Go to Settings > General > Background App Refresh. Tap Background App Refresh > Off to turn Background App Refresh off completely.
All replies. Check in Settings>iTunes & App Store>Automatic Downloads>Updates>On. If that is set to "On", any apps that require updates are being downloaded in the background.
Add below in your - (void)applicationDidEnterBackground:(UIApplication *)application
UIApplication *app = [UIApplication sharedApplication]; UIBackgroundTaskIdentifier bgTask; bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ [app endBackgroundTask:bgTask]; }];
and you are good to go... I have this in one of my published download manager app
This will work just fine. You can also check how much time you have, since apple only enable 10 minutes background tasks. Use:
NSTimeInterval ti = [[UIApplication sharedApplication]backgroundTimeRemaining]; NSLog(@"backgroundTimeRemaining: %f", ti); // just for debug
It is possible to start a background task when you begin the download:
Apps that are transitioning to the background can request an extra amount of time to finish any important last-minute tasks.
Executing a Finite-Length Task in the Background
However, such a task is limited to an undefined amount of execution time by the system. However, a 200Mb file download may be too large a task in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With