I want to be able to call an app intent for another app from within my app, within the Swift code, not from the Shortcuts app.
Generated on 7/30/2024
1 search
To call an app intent for another app from within your app using Swift, you can leverage the App Intents framework. This framework allows you to define intents that can be used across various system experiences, including Siri, Spotlight, and the Shortcuts app.
Here are the steps to achieve this:
-
Define the Intent: Create an intent that conforms to the
AppIntent
protocol. This intent will encapsulate the action you want to perform. -
Implement the Intent: Implement the logic for the intent in your app. This includes defining any parameters and the action to be performed.
-
Expose the Intent: Make the intent available to the system by registering it. This allows it to be used by Siri, Spotlight, and other system features.
Here is an example of how you might define and implement an intent in Swift:
import AppIntents
struct OpenPinnedTrailIntent: AppIntent {
static var title: LocalizedStringResource = "Open Pinned Trail"
@Parameter(title: "Trail ID")
var trailID: String
func perform() async throws -> some IntentResult {
// Logic to open the pinned trail in your app
// For example, navigate to the trail details screen
return .result()
}
}
- Use the Intent in Your App: You can call this intent from within your app using the
AppIntent
framework. Here is an example of how to invoke the intent:
let intent = OpenPinnedTrailIntent(trailID: "12345")
Task {
do {
let result = try await intent.perform()
// Handle the result
} catch {
// Handle any errors
}
}
For more detailed guidance, you can refer to the session "Bring your app’s core features to users with App Intents" which covers how to build and use app intents in your app.
Relevant Sessions
- Bring your app’s core features to users with App Intents
- Design App Intents for system experiences
- Bring your app to Siri
These sessions provide comprehensive information on how to define, implement, and use app intents within your app and across the system.

Bring your app’s core features to users with App Intents
Learn the principles of the App Intents framework, like intents, entities, and queries, and how you can harness them to expose your app’s most important functionality right where people need it most. Find out how to build deep integration between your app and the many system features built on top of App Intents, including Siri, controls and widgets, Apple Pencil, Shortcuts, the Action button, and more. Get tips on how to build your App Intents integrations efficiently to create the best experiences in every surface while still sharing code and core functionality.

Design App Intents for system experiences
App Intents power system experiences in controls, Spotlight, Siri, and more. Find out how to identify the functionality that’s best for App Intents, and how to use parameters to make these intents flexible. Learn how to use App Intents to allow people to take action outside your app, and see examples of when to navigate into your app to show contextual information.

Bring your app to Siri
Learn how to use App Intents to expose your app’s functionality to Siri. Understand which intents are already available for your use, and how to create custom intents to integrate actions from your app into the system. We’ll also cover what metadata to provide, making your entities searchable via Spotlight, annotating onscreen references, and much more.