I have a react native app but right now I am mainly focused on the iOS module.
First I created an intent using an intent definition file but then I decided to convert this to an app intent.
Overall it works as expected when I manually go to the shortcuts app, search for the app and add my intent which has a template.
After adding that using the shortcuts app I make siri ask for my parameter and then it lunches the app and I receive the parameter said by the user in my swift/ obj c code.
My problem is now I don’t know how/where can I donate this intent as shortcut in order to avoid having user manually do all the steps above.
Here is how my app intent code looks like (Which is generated by converting my intent definition file to an app intent)
import Foundation
import AppIntents
import UIKit
@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
struct [AppName]Command: AppIntent, CustomIntentMigratedAppIntent, PredictableIntent {
static let intentClassName = "[AppName]CommandIntent"
static var openAppWhenRun = true
static var title: LocalizedStringResource = "[AppName] Command"
static var description = IntentDescription("A command should be done by [AppName]")
@Parameter(title: "Command")
var command: String?
static var parameterSummary: some ParameterSummary {
Summary("(.$command) by [AppName]")
}
static var predictionConfiguration: some IntentPredictionConfiguration {
IntentPrediction(parameters: (.$command)) { command in
DisplayRepresentation(
title: "(command!) by [AppName]",
subtitle: "The (command!) should be done by [AppName]"
)
}
}
func perform() async throws -> some IntentResult {
print("SI.Command Performed: (command ?? "No Command")") // Log for debugging
NotificationCenter.default.post(name: Notification.Name("[AppName]CommandTriggered"),
object: nil,
userInfo: ["command": command ?? ""])
// Example feedback to Siri
return .result()
}
}
@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
fileprivate extension IntentDialog {
static var commandParameterConfiguration: Self {
"Work orders, Assets, Invoices"
}
static func commandParameterPrompt(command: String) -> Self {
"What is your (command) for [AppName]?"
}
static var responseSuccess: Self {
"Done"
}
}
I tried creating an app intent and I expect it to be appeared in the shortcuts app and be detected by siri without doing it manually.
2
Answers
AppIntents are "donated" automatically at build time. They no longer require the user to manually "add" them for them to show up in Siri or the Shortcuts app. You can still donate actions specific to your app so that siri can learn the user’s behavior over time and suggest those actions to the user.
See more here: https://developer.apple.com/documentation/appintents/intent-discovery
You can use AppShortcutsProvider to add your intent as appShortcuts