1

Before asking a question, let me clarify what I understand about iOS App states:


Backgrounded: In this state, your app is not in the foreground anymore but it is still able to run code.

Suspended: Your app enters this state when it’s no longer able to run code.


Now, I wanted to keep downloading going on when App is in background, i.e. it still does exist in multitasking screen. It is working as expected with background transfer service.

But, in some tutorial reference, I have read that you can perform downloading even when App is Backgrounded / Suspended. Can it work even when my App is suspended, i.e. removed from multitasking screen ?

I have been reading many documents including Apple class reference regarding background transfer service with download task, but no one clarifies that the download will not work when App is suspended (killed).

Appreciate your thoughts and advices !!!

NSPratik
  • 4,714
  • 7
  • 51
  • 81

2 Answers2

3

If your app has been suspended by the system (without force quiting from multitasking screen) your background session will continue to work.

If you force quit the application all download tasks will be canceled.

The following is from backgroundSessionConfigurationWithIdentifier(_:) documentation :

If an iOS app is terminated by the system and relaunched, the app can use the same identifier to create a new configuration object and session and retrieve the status of transfers that were in progress at the time of termination. This behavior applies only for normal termination of the app by the system. If the user terminates the app from the multitasking screen, the system cancels all of the session’s background transfers. In addition, the system does not automatically relaunch apps that were force quit by the user. The user must explicitly relaunch the app before transfers can begin again.

stefos
  • 1,235
  • 1
  • 10
  • 18
1

Apps displayed in the multitasking UI aren’t necessarily executing code or fetching data. Listed apps may be suspended or not running at all

[[UIApplication sharedApplication] applicationState] will check your application state, you can test your app.

NSURLSession class can hand off downloads and uploads to the operating system when the app becomes inactive. As with almost all background execution APIs, if the user force quits from the multitasking UI, the background operation will terminate

In iOS 7, Apple added support for background fetch—a kind of smart, per-app crontab that wakes up at opportunistic times. There is no way to force background fetches to execute at exact intervals. iOS checks how much data and battery power was used during previous background fetches when scheduling future callbacks.

Background fetches can also be triggered by remote push notification and have a very similar delegate method with the same completion handler.

Full Tutorial is here

https://blog.newrelic.com/2016/01/13/ios9-background-execution/

SpaceDust__
  • 4,844
  • 4
  • 43
  • 82