I'm on Xcode 14.2 and running iOS 16.2 on my device (No betas). The intent does not appear in the shortcuts App.
Here's my code..
import AppIntents
@available(iOS 16.0, *)
struct ShowRecentOrder: AppIntent {
static var title: LocalizedStringResource = "Show my orders"
static var description = IntentDescription("Shows list of orders")
@MainActor
func perform() async throws -> some IntentResult & ProvidesDialog {
let total = await getRecentOrder()
let dialog = IntentDialog(total)
return .result(dialog: dialog)
}
private func getRecentOrder() async -> LocalizedStringResource {
let result = await OrderServiceMock.fetchRecentOrder()
return LocalizedStringResource(stringLiteral: String(format: "%2.f", result))
}
}
@available(iOS 16.0, *)
struct ShortcutsService: AppShortcutsProvider {
// Maximum of 10 App Shortcuts supported by Apple
@AppShortcutsBuilder static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: ShowRecentOrder(),
phrases: [
"Show my recent order in \(.applicationName)",
"View my recent order in \(.applicationName)"
]
)
}
static var shortcutTileColor: ShortcutTileColor { .tangerine }
}
class OrderServiceMock {
static func fetchRecentOrder() async -> String {
let mockOrders = ["Order 1", "order 2", "Order 3"]
return mockOrders.randomElement() ?? ""
}
}