Type Method

background(withIdentifier:)

Creates a session configuration object that allows HTTP and HTTPS uploads or downloads to be performed in the background.

Declaration

class func background(withIdentifier identifier: String) -> URLSessionConfiguration

Parameters

identifier

The unique identifier for the configuration object. This parameter must not be nil or an empty string.

Return Value

A configuration object that causes the system to perform upload and download tasks in a separate process.

Discussion

Use this method to initialize a configuration object suitable for transferring data files while the app runs in the background. A session configured with this object hands control of the transfers over to the system, which handles the transfers in a separate process. In iOS, this configuration makes it possible for transfers to continue even when the app itself is suspended or terminated.

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 to 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.

You can configure an background session to schedule transfers at the discretion of the system for optimal performance using the isDiscretionary property. When transferring large amounts of data, you are encouraged to set the value of this property to true. For an example of using the background configuration, see Downloading Files in the Background.

See Also

Creating a Session Configuration Object

class var `default`: URLSessionConfiguration

A default session configuration object.

class var ephemeral: URLSessionConfiguration

A session configuration that uses no persistent storage for caches, cookies, or credentials.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software