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.
- An app goes to the background. What can it still do, and how do you choose a mechanism?
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… - What do the audio, location, VoIP and remote-notification background modes allow, and what is the catch?
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.
- How does BGTaskScheduler work, and why does your task not run when you ask?
You register a handler for each task identifier at launch (in didFinishLaunching, before it returns), list the identifiers in… - How does a background URLSession keep working when the app is not running?
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
- 6.1 · The process, the sandbox, entitlements and privacy prompts
- 6.2 · App and scene lifecycle in UIKit and SwiftUI
- 6.3 · The run loop, its modes, and the main-thread contract
- 6.4 · The launch path: dyld, initialisers and the first frame
- 6.6 · Memory warnings, jetsam and the watchdog
- 6.7 · Info.plist, URL schemes, universal links and associated domains
- 6.8 · App groups, keychain groups and extensions as separate processes
- 6.9 · How a process dies, what it costs, what confines it and what seals it
- 6.10 · Threads and run loops, observers, and what actually runs in a custom mode
- 6.11 · Launch arguments, the scene callbacks, and reading a binary and its plists