I'm adding AppIntents to my existing "ShopList" app and I'm having two problems that I think are related.
-
I can't get shortcuts (or Siri) to work when I pass a parameter to an intent. It works if I don't pass a parameter though.
-
My StoreEntityQuery.suggestedEntities function is not being called during initialization.
I have an AppIntentsShortcutProvider defined as follows.
class ShopListShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(intent: FindStore(), phrases: [
"Find \(\.$store) store in \(.applicationName)"
],
shortTitle: "Find Store",
systemImageName: "cart")
}
}
Details below. I would appreciate any suggestions on what I'm missing or doing wrong.
In my AppDelegate "didFinishLaunchingWithOptions" function, I call ShopListShortcuts.updateShortcutParameters.
The FindStore struct is defined as follows.
struct FindStore: AppIntent {
static var title: LocalizedStringResource = "Find Store"
static var description = IntentDescription("Finds a store.")
static var openAppWhenRun: Bool = false
@Parameter(title: "Store", description: "The store.")
var store: StoreEntity
@MainActor
func perform() async throws -> some IntentResult {
print("performing intent with \(store.id) and \(store.name)")
return .result()
}
}
The StoreEntity is defined as follows.
struct StoreEntity: AppEntity {
...
static var defaultQuery = StoreEntityQuery()
var id: Store.ID
@Property(title: "Store Name")
var name: String
...
}
And finally the StoreEntityQuery is defined as follows.
struct StoreEntityQuery: EntityQuery {
func entities(for identifiers: [StoreEntity.ID]) async throws -> [StoreEntity] {
print("entities call")
return ...
}
func suggestedEntities(for identifiers: [StoreEntity.ID]) async throws -> [StoreEntity] {
print("suggested entities call")
return ...
}
}