RunSystemShortcutIntent
An app intent you use in widgets to open another app or perform an App Shortcut, custom shortcut, or system action.
Declaration
struct RunSystemShortcutIntentOverview
Only use RunSystemShortcutIntent to initialize a Button with the init(_:intent:) initializer and place the button in a widget. The run system shortcut intent doesn’t provide functionality in other contexts.
When a person configures the widget, they choose the button’s action. It can:
Open another installed app.
Perform an App Shortcut.
Perform a custom shortcut a person creates in Shortcuts.
Perform a system action.
The following example shows how an app offers a widget that allows people to launch another app from a button:
import SwiftUI
import WidgetKit
import AppIntents
struct LauncherWidgetConfigurationIntent: WidgetConfigurationIntent {
static var title: LocalizedStringResource { "Launcher Widget" }
static var description: IntentDescription { "Widget that runs a shortcut or opens an app" }
@Parameter(title: "Action")
var shortcut: SystemShortcut
}
struct LauncherWidget: Widget {
let kind: String = "LauncherWidget"
var body: some WidgetConfiguration {
AppIntentConfiguration(
kind: kind,
intent: LauncherWidgetConfigurationIntent.self,
provider: Provider()
) { entry in
Button(
intent: RunSystemShortcutIntent(shortcut: entry.configuration.shortcut)
) {
VStack {
Image(systemName: "play.fill")
.font(.largeTitle)
Text(entry.configuration.shortcut.displayRepresentation.title)
.font(.caption)
}
}
}
}
}The RunSystemShortcutIntent represents a person’s chosen action when they configure your widget and it provides metadata the system needs for the widget’s configuration UI. It doesn’t provide your widget or app with access to a shortcut’s actions, parameters, or implementation details. If a custom shortcut or App Shortcut requires an interaction, for example, if it prompts a person for input, the system may open the Shortcuts app to perform the intent.