Contents

backgroundTask(_:action:)

Runs the given action when the system provides a background task.

Declaration

nonisolated func backgroundTask<D, R>(_ task: BackgroundTask<D, R>, action: @escaping  @Sendable (D) async -> R) -> some WidgetConfiguration where D : Sendable, R : Sendable

Parameters

  • task:

    The type of task the action responds to.

  • action:

    The closure that is called when the system provides a task matching the provided task.

Discussion

When the system wakes your app or extension for one or more background tasks, it will call any actions associated with matching tasks. When your async actions return, the system will put your app back into a suspended state. In Widget Extensions, this modifier can be used to handle URL Session background tasks with urlSession.

See Also

Managing background tasks