Hello,
My goal is to enable users to perform a freeform search request for any product I sell using a spoken phrase, for example, "Hey Siri, search GAMING CONSOLES on MyCatalogApp". The result would launch MyCatalogApp and navigate to a search results page displaying gaming consoles.
I have defined a SearchIntent (using the .system.search schema) and a Shortcut to accomplish this.
However, Siri doesn't seem to be able to correctly parse the spoken phrase, extract the search string, and provide it as the critiria term within SearchIntent.
What am I doing wrong?
Here is the SearchIntent. Note the print() statement outputs the search string--which in the scenario above would be "GAMING CONSOLES"--but it doesn't work.
import AppIntents
@available(iOS 17.2, *)
@AppIntent(schema: .system.search)
struct SearchIntent: ShowInAppSearchResultsIntent {
static var searchScopes: [StringSearchScope] = [.general]
@Parameter(title: "Criteria")
var criteria: StringSearchCriteria
static var title: LocalizedStringResource = "Search with MyCatalogApp"
@MainActor
func perform() async throws -> some IntentResult {
let searchString = criteria.term
print("**** Search String: \(searchString) ****") // tmp debugging
try await MyCatalogSearchHelper.search(for: searchString) // fetch results via my async fetch API
return .result()
}
}
Here's the Shortcuts definition:
import AppIntents
@available(iOS 17.2, *)
struct Shortcuts: AppShortcutsProvider {
@AppShortcutsBuilder
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: SearchIntent(),
phrases: ["Search for \(\.$criteria) on \(.applicationName)."],
shortTitle: "Search", systemImageName: "magnifyingglass"
)
}
}
Thanks for any help!