Open onmyway133 opened 11 months ago
Declare AppShortcutsProvider, note that appShortcuts uses @AppShortcutsBuilder syntax
AppShortcutsProvider
appShortcuts
@AppShortcutsBuilder
import AppIntents struct OurShortcutsProvider: AppShortcutsProvider { static var shortcutTileColor: ShortcutTileColor = .lightBlue @AppShortcutsBuilder static var appShortcuts: [AppShortcut] { AppShortcut(intent: AskIntent(), phrases: [ "Hey Joy", "Ask \(.applicationName)" ]) } }
We can create an app intent in code
import AppIntents import OpenAI struct AskIntent: AppIntent { static var title: LocalizedStringResource = "Hey Joy" static var description: IntentDescription = "Ask me anything" @Parameter(title: "Prompt") var prompt: String? static var parameterSummary: some ParameterSummary { Summary("Ask question \(\.$prompt)") } func perform() async throws -> some ProvidesDialog { guard let prompt else { throw $prompt.needsValueError("Please provide a question") } let client = ChatService() let content = try await client.ask(prompt: prompt) if let content { return .result(dialog: IntentDialog(stringLiteral: content)) } else { return .result(dialog: "No valid answer") } } }
If the intents have dynamic parameters, we can tell AppIntents to refresh its parameters list, using [updateAppShortcutParameters](https://developer.apple.com/documentation/appintents/appshortcutsprovider/updateappshortcutparameters())
OurShortcutsProvider.updateAppShortcutParameters()
Use SiriTipView
SiriTipView(intent: ReorderIntent(), isVisible: $isVisible) .siriTipViewStyle(.black)
Use ShortcutsLink
ShortcutsLink() .shortcutsLinkStyle(.whiteOutline)
Look for appintentsmetadataprocessor in build log for potential errors
appintentsmetadataprocessor
Some possible warnings
Metadata extraction skipped. No AppIntents.framework dependency found.
AppIntents
Declare
AppShortcutsProvider
, note thatappShortcuts
uses@AppShortcutsBuilder
syntaxWe can create an app intent in code
Update parameters
If the intents have dynamic parameters, we can tell AppIntents to refresh its parameters list, using [updateAppShortcutParameters](https://developer.apple.com/documentation/appintents/appshortcutsprovider/updateappshortcutparameters())
Show tip view
Use SiriTipView
Show link to open Shortcuts app
Use ShortcutsLink
Troubleshoot
Look for
appintentsmetadataprocessor
in build log for potential errorsSome possible warnings