My question is similar to https://developer.apple.com/forums/thread/757298?answerId=791343022#791343022 but the solution from there did not help me.
My app sends messages. I need it to do so when a user says to Siri: "Send message with ". When a user says so, Siri shows "Open button and says " hasn't added support for that with Siri".
The code is pretty short and must work, but it doesn't. Could you please help and explain how to add the support mentioned above? How else I can use AppIntent and register the app as one capable to send messages when asked by Siri?
import AppIntents
@main
struct MyAppNameApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
init() {
MyAppNameShortcuts.updateAppShortcutParameters()
Task {
await MyAppNameShortcuts.updateAppShortcutParameters()
}
}
}
struct SendMessageWithMyAppName: AppIntent {
static var title: LocalizedStringResource = "Send message"
static let description = IntentDescription(
"Dictate a message and have MyAppName print it to the Xcode console.")
@Parameter(title: "Message", requestValueDialog: "What should I send?")
var content: String
static var openAppWhenRun = false
func perform() async throws -> some IntentResult {
print("MyAppName message: \(content)")
await MainActor.run {
NotificationCenter.default.post(name: .newMessageReceived, object: content)
}
return .result(dialog: "Message sent: \(content)")
}
}
struct MyAppNameShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: SendMessageWithMyAppName(),
phrases: [
"Send message with \(.applicationName)"
],
shortTitle: "Send Message",
systemImageName: "message"
)
}
}
Selecting any option will automatically load the page