I'm currently testing this on a physical device (12 Pro Max, iOS 26). Through shortcuts, I know for a fact that I am able to successfully trigger the perform code to do what's needed. In addition, if I just tell siri the phrase without my unit parameter, and it asks me which unit, I am able to, once again, successfully call my perform. The problem is any of my phrases that I include my unit, it either just opens my application, or says "I can't understand"
Here is my sample code:
My Entity:
import Foundation
import AppIntents
struct Unit: Codable, Identifiable {
let nickname: String
let ipAddress: String
let id: String
}
struct UnitEntity: AppEntity {
static var typeDisplayRepresentation: TypeDisplayRepresentation {
TypeDisplayRepresentation(
name: LocalizedStringResource("Unit", table: "AppIntents")
)
}
static let defaultQuery = UnitEntityQuery()
// Unique Identifer
var id: Unit.ID
// @Property allows this data to be available to Shortcuts, Siri, Etc.
@Property var name: String
// By not including @Property, this data is NOT used for queries.
var ipAddress: String
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(
title: "\(name)"
)
}
init(Unit: Unit) {
self.id = Unit.id
self.ipAddress = Unit.ipAddress
self.name = Unit.nickname
}
}
My Query:
struct UnitEntityQuery: EntityQuery {
func entities(for identifiers: [UnitEntity.ID]) async throws -> [UnitEntity] {
print("[UnitEntityQuery] Query for IDs \(identifiers)")
return UnitManager.shared.getUnitUnits()
.map { UnitEntity(Unit: $0) }
}
func suggestedEntities() async throws -> [UnitEntity] {
print("[UnitEntityQuery] Request for suggested entities.")
return UnitManager.shared.getUnitUnits()
.map { UnitEntity(Unit: $0) }
}
}
UnitsManager:
class UnitManager {
static let shared = UnitManager()
private init() {}
var allUnits: [UnitEntity] {
getUnitUnits().map { UnitEntity(Unit: $0) }
}
func getUnitUnits() -> [Unit] {
guard let jsonString = UserDefaults.standard.string(forKey: "UnitUnits"),
let data = jsonString.data(using: .utf8) else {
return []
}
do {
return try JSONDecoder().decode([Unit].self, from: data)
} catch {
print("Error decoding units: \(error)")
return []
}
}
func contactUnit(unit: UnitEntity) async -> Bool {
// Do things here...
}
}
My AppIntent:
import AppIntents
struct TurnOnUnit: AppIntent {
static let title: LocalizedStringResource = "Turn on Unit"
static let description = IntentDescription("Turn on an Unit")
static var parameterSummary: some ParameterSummary {
Summary("Turn on \(\.$UnitUnit)")
}
@Parameter(title: "Unit Unit", description: "The Unit Unit to turn on")
var UnitUnit: UnitEntity
func perform() async throws -> some IntentResult & ProvidesDialog {
//... My code here
}
}
And my ShortcutProvider:
import Foundation
import AppIntents
struct UnitShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: TurnOnUnit(),
phrases: [
"Start an Unit with \(.applicationName)",
"Using \(.applicationName), turn on my \(\.$UnitUnit)",
"Turn on my \(\.$UnitUnit) with \(.applicationName)",
"Start my \(\.$UnitUnit) with \(.applicationName)",
"Start \(\.$UnitUnit) with \(.applicationName)",
"Start \(\.$UnitUnit) in \(.applicationName)",
"Start \(\.$UnitUnit) using \(.applicationName)",
"Trigger \(\.$UnitUnit) using \(.applicationName)",
"Activate \(\.$UnitUnit) using \(.applicationName)",
"Volcano \(\.$UnitUnit) using \(.applicationName)",
],
shortTitle: "Turn on unit",
systemImageName: "bolt.fill"
)
}
}