Send requests from your app when it is running in the background.
Use background requests when your app is running in the background or about to become inactive.
To create a background session:
Create a background session by calling the
init(configuration:initializer, passing both the background configuration and a session delegate. Background sessions must have a session delegate.
delegate: delegate Queue:)
Create a task to download data by calling the session object’s
Start the task by calling its
Implement the session delegate’s methods to receive data and notifications from the session. For more information, see
Unlike default and ephemeral sessions, a background session persists even if your watchOS app closes. If your app is still the frontmost app, the system wakes your app as soon as it receives a response. Otherwise the system may defer delivering the response to your app, based on system resources. If the response has not yet been delivered, it is delivered the next time your app becomes active.
Background sessions may be deferred based on the system’s state, network connectivity, and other issues. When making a background request, smaller transfers are better.
For more information on working with WatchKit background tasks, see Background Tasks.