Background URLSession
Also known as: background download ios, urlsession background, ios background urlsession
A Background URLSession is a URLSession configured with background(withIdentifier:) so transfers run in a separate system daemon and continue after the app is suspended or terminated, with the OS relaunching the app on completion.
- Configured via URLSessionConfiguration.background(withIdentifier:) with a unique identifier.
- Transfers run in the nsurlsessiond daemon and survive app suspension or termination.
- Only upload and download tasks are supported; you must use a delegate, not completion handlers.
How it works
You create the session with URLSessionConfiguration.background(withIdentifier:), passing a stable, app-unique identifier. The configuration is handed to a URLSession along with a delegate, because background sessions do not support completion-handler tasks. Only upload and download tasks are allowed, not plain data tasks.
Once a task starts, the work is handed off to the system process nsurlsessiond, which performs the transfer independently of your app's lifecycle. If the user leaves the app or iOS suspends it, the download keeps going. When the transfer finishes, the system relaunches your app in the background and calls application(_:handleEventsForBackgroundURLSession:completionHandler:), where you reconnect the same session identifier to receive the delegate callbacks.
Why it matters for storage
Background transfers are how apps quietly pull large media -- video, podcasts, offline maps, model files -- while you are doing something else. A completed downloadTask writes its result to a temporary file that your delegate must move into a permanent location with FileManager; if you copy it into Documents or an un-purged Caches folder, it counts against device storage.
Because these downloads accumulate without active user attention, they are a common source of the "where did my space go" problem. A cleaner like Cleanor surfaces the large cached and downloaded files these sessions leave behind so you can clear what you no longer need.