onAppIntentExecution(_:perform:)
Registers a handler to run when the app receives an app intent that targets the associated scene.
Declaration
nonisolated func onAppIntentExecution<I>(_ intent: I.Type = I.self, perform action: @escaping @MainActor (I) -> Void) -> some View where I : TargetContentProvidingIntent
Parameters
- intent:
The type of app intent that the
actionclosure handles. - action:
A closure for SwiftUI to call when it receives the specified type of app intent. The closure takes the received app intent instance as an input parameter.
Return Value
A view that handles the specified app intent.
Discussion
Add this modifier to a view and use it to receive app intents intended for one of your scenes. In your handler, use the contents of the app intent to configure the views of your scene. For example, retrieve the item from an OpenIntent type and display it in your views. Your closure runs before the app comes to the foreground and before the system calls the app intent’s AppIntent/perform() method, so you can use the closure to configure your interface in advance.
To route app intents to a particular scene, add the handlesExternalEvents(preferring:allowing:) modifier to your view or the handlesExternalEvents(matching:) modifier to your Scene type. For each modifier, you supply one or more strings to match against the target content modifier of an incoming app intent. SwiftUI delivers only matching app intents to this modifier.