A background task that helps you respond to URLSession background transfers.


class WKURLSessionRefreshBackgroundTask : WKRefreshBackgroundTask


Always upload and download data using an URLSession background transfer. Background transfers occur in a separate process. They continue to transfer the data even after your app has terminated. Asynchronous uploads and downloads, on the other hand, are suspended with your app. Given the short run time of watchOS apps, you cannot guarantee that an asynchronous transfer will finish before the app is suspended. For more information on background transfers, see Background Transfer Considerations.

Do not subclass or create instances of this class. Instead, the system instantiates a WKURLSessionRefreshBackgroundTask object, and passes the task object to your extension delegate’s handle(_:) method in response to URLSession events. The system creates a background URLSession task when any of the following events occur:

  • Authentication is required to complete a background transfer.

  • All background transfers associated with a session identifier have completed (either successfully or unsuccessfully).

To get more information about the transfer, create a background configuration object with the same session identifier. Next, create a session object using the configuration object and a session delegate. The new session is automatically reassociated with the transfer, and the appropriate delegate methods are called.

You will need to defer calling the background URLSession task’s setTaskCompleted() method until after you are done processing these delegate method calls.


Accessing Background Task Data

var sessionIdentifier: String

The identifier for the triggering background transfer.


Conforms To

See Also

Background Tasks

Running watchOS Apps in the Background

Schedule and perform background tasks from within your app.

Playing Background Audio

Enable background audio in your app to provide a seamless playback experience.

Preparing to Take Your watchOS App’s Snapshot

Use snapshot background tasks to provide a timely, accurate snapshot of your app.

class WKRefreshBackgroundTask

The abstract superclass for WatchKit's other background task classes.

class WKApplicationRefreshBackgroundTask

A background task used to update your app’s state in the background.

class WKWatchConnectivityRefreshBackgroundTask

A background task used to receive background updates from the Watch Connectivity framework.

class WKSnapshotRefreshBackgroundTask

A background task used to update your app’s user interface in preparation for a snapshot.

class WKIntentDidRunRefreshBackgroundTask

A background task used to update your app after a SiriKit intent runs.

class WKRelevantShortcutRefreshBackgroundTask

A background task used to periodically donate relevant Siri shortcuts.

Background Session Keys

Enable background sessions.