6.5 · Background modes, BGTaskScheduler and background transfers

An iOS app that is not on screen is, by default, frozen within seconds. Everything that works in the background is a deliberate exception granted by the system, and each exception comes with its own rules.

Mental model. You do not keep an app running in the background. You ask the system to wake you for a specific kind of work, and it decides when, and for how long.

Choosing a mechanism

Which exception fits which job.

  1. An app goes to the background. What can it still do, and how do you choose a mechanism? 6.5.1 · L3
    Within seconds of backgrounding the app is suspended: it executes nothing and holds no CPU. To do more, you use one of a small set of sanctioned mechanisms…
  2. What do the audio, location, VoIP and remote-notification background modes allow, and what is the catch? 6.5.2 · L3
    Declaring a mode in UIBackgroundModes lets the app keep running (or be woken) for that purpose. Audio: the app can keep playing while backgrounded, only while…

Scheduled and transfer work

Tasks the system runs for you, and downloads that outlive your process.

  1. How does BGTaskScheduler work, and why does your task not run when you ask? 6.5.3 · L3
    You register a handler for each task identifier at launch (in didFinishLaunching, before it returns), list the identifiers in…
  2. How does a background URLSession keep working when the app is not running? 6.5.4 · L3
    A session created with URLSessionConfiguration.background(withIdentifier:) hands its transfers to a system daemon, which performs them outside your process.…

More in iOS platform internals