Background Tasks
Background tasks are a way for you to keep your app’s interfaces up-to-date. Receiving a background task object from the system is your signal to perform specific types of operations. The task object defines the type of task to perform and contains any data needed to complete the task. The system delivers background task objects to your app by calling the handleBackgroundTasks:
method of your app’s extension delegate.
watchOS supports the following types of background tasks:
Background App Refresh Tasks. Use a
WKApplicationRefreshBackgroundTask
object to handle general updates to your app’s state. For example, you might use this type of task to check in with your company’s server or begin downloading new content. You schedule this type of background task explicitly from your your app’sWKExtension
object.Background Snapshot Refresh Tasks. Use a
WKSnapshotRefreshBackgroundTask
object to update your app’s interface in preparation of having its snapshot taken. The system automatically takes the snapshot when this task completes. The system schedules background snapshot refresh tasks periodically to update your snapshot. You can also schedule a task of this type explicitly from your app’sWKExtension
object when your interface changes.Background Watch Connectivity Tasks. Use a
WKWatchConnectivityRefreshBackgroundTask
object to receive data sent by your iOS app using the Watch Connectivity framework. The system automatically creates this type of task when your Watch app receives data from the its corresponding iOS app running on the paired iPhone. You do not schedule tasks of this type yourself.Background NSURLSession Tasks. Use a
WKURLSessionRefreshBackgroundTask
object to receive data you previously requested using anNSURLSession
object. This task is triggered when a background transfer requires authorization or when a background transfer completes (successfully or unsuccessfully). You do not schedule tasks of this type yourself.
For more information on background tasks, see Background Refresh Tasks in WKExtensionDelegate Protocol Reference.