<!--
{
  "documentType" : "article",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/System-events",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "System events"
}
-->

# System events

React to system events, like opening a URL.

## Overview

Specify view and scene modifiers to indicate how your app responds to certain
system events. For example, you can use the [`onOpenURL(perform:)`](/documentation/SwiftUI/View/onOpenURL(perform:))
view modifier to define an action to take when your app receives a universal
link, or use the [`backgroundTask(_:action:)`](/documentation/SwiftUI/Scene/backgroundTask(_:action:)) scene modifier to specify
an asynchronous task to carry out in response to a background
task event, like the completion of a background URL session.

![](images/com.apple.SwiftUI/system-events-hero@2x.png)

## Topics

### Sending and receiving user activities

[Restoring your app’s state with SwiftUI](/documentation/SwiftUI/restoring-your-app-s-state-with-swiftui)

Provide app continuity for users by preserving their current activities.

[`func userActivity<P>(String, element: P?, (P, NSUserActivity) -> ()) -> some View`](/documentation/SwiftUI/View/userActivity(_:element:_:))

Advertises a user activity type.

[`func userActivity(String, isActive: Bool, (NSUserActivity) -> ()) -> some View`](/documentation/SwiftUI/View/userActivity(_:isActive:_:))

Advertises a user activity type.

[`func onContinueUserActivity(String, perform: (NSUserActivity) -> ()) -> some View`](/documentation/SwiftUI/View/onContinueUserActivity(_:perform:))

Registers a handler to invoke in response to a user activity that your
app receives.

### Sending and receiving URLs

[`var openURL: OpenURLAction`](/documentation/SwiftUI/EnvironmentValues/openURL)

An action that opens a URL.

[`struct OpenURLAction`](/documentation/SwiftUI/OpenURLAction)

An action that opens a URL.

[`func onOpenURL(perform: (URL) -> ()) -> some View`](/documentation/SwiftUI/View/onOpenURL(perform:))

Registers a handler to invoke in response to a URL that your app
receives.

### Handling external events

[`func handlesExternalEvents(matching: Set<String>) -> some Scene`](/documentation/SwiftUI/Scene/handlesExternalEvents(matching:))

Specifies the external events for which SwiftUI opens a new instance
of the modified scene.

[`func handlesExternalEvents(preferring: Set<String>, allowing: Set<String>) -> some View`](/documentation/SwiftUI/View/handlesExternalEvents(preferring:allowing:))

Specifies the external events that the view’s scene handles
if the scene is already open.

### Handling background tasks

[`func backgroundTask<D, R>(BackgroundTask<D, R>, action: (D) async -> R) -> some Scene`](/documentation/SwiftUI/Scene/backgroundTask(_:action:))

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

[`struct BackgroundTask`](/documentation/SwiftUI/BackgroundTask)

The kinds of background tasks that your app or extension can handle.

[`struct SnapshotData`](/documentation/SwiftUI/SnapshotData)

The associated data of a snapshot background task.

[`struct SnapshotResponse`](/documentation/SwiftUI/SnapshotResponse)

Your application’s response to a snapshot background task.

### Importing and exporting transferable items

[`func importableFromServices<T>(for: T.Type, action: ([T]) -> Bool) -> some View`](/documentation/SwiftUI/View/importableFromServices(for:action:))

Enables importing items from services, such as Continuity Camera
on macOS.

[`func exportableToServices<T>(@autoclosure () -> [T]) -> some View`](/documentation/SwiftUI/View/exportableToServices(_:))

Exports items for consumption by shortcuts,
quick actions, and services.

[`func exportableToServices<T>(@autoclosure () -> [T], onEdit: ([T]) -> Bool) -> some View`](/documentation/SwiftUI/View/exportableToServices(_:onEdit:))

Exports read-write items for consumption by shortcuts,
quick actions, and services.

### Importing and exporting using item providers

[`func importsItemProviders([UTType], onImport: ([NSItemProvider]) -> Bool) -> some View`](/documentation/SwiftUI/View/importsItemProviders(_:onImport:))

Enables importing item providers from services, such as Continuity Camera
on macOS.

[`func exportsItemProviders([UTType], onExport: () -> [NSItemProvider]) -> some View`](/documentation/SwiftUI/View/exportsItemProviders(_:onExport:))

Exports a read-only item provider for consumption by shortcuts,
quick actions, and services.

[`func exportsItemProviders([UTType], onExport: () -> [NSItemProvider], onEdit: ([NSItemProvider]) -> Bool) -> some View`](/documentation/SwiftUI/View/exportsItemProviders(_:onExport:onEdit:))

Exports a read-write item provider for consumption by shortcuts,
quick actions, and services.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)