Siri directions: speak the station before Maps hand-off (.result(opensIntent:dialog:))
This commit is contained in:
@@ -148,7 +148,7 @@ struct DirectionsToCheapestFuelIntent: AppIntent {
|
|||||||
self.fuel = fuel
|
self.fuel = fuel
|
||||||
}
|
}
|
||||||
|
|
||||||
func perform() async throws -> some IntentResult & OpensIntent {
|
func perform() async throws -> some IntentResult & ProvidesDialog & OpensIntent {
|
||||||
let stations = FuelStore.loadStations()
|
let stations = FuelStore.loadStations()
|
||||||
|
|
||||||
guard !stations.isEmpty else {
|
guard !stations.isEmpty else {
|
||||||
@@ -172,8 +172,17 @@ struct DirectionsToCheapestFuelIntent: AppIntent {
|
|||||||
throw DirectionsError("I couldn't find any station selling \(fuelName) within \(radiusText) of you.")
|
throw DirectionsError("I couldn't find any station selling \(fuelName) within \(radiusText) of you.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Speak where we're taking the user BEFORE the Maps hand-off — a
|
||||||
|
// silent jump straight into Maps is jarring. The `.result(opensIntent:
|
||||||
|
// dialog:)` overload (confirmed in the iOS 26 SDK interface) lets the
|
||||||
|
// intent do both: announce the station, then open it.
|
||||||
|
let distanceKM = station.distanceKM(to: coordinate.lat, lng2: coordinate.lng)
|
||||||
|
let distanceText = FuelStore.loadDistanceUnit().format(distanceKM)
|
||||||
let url = SiriCheapestLookup.mapsURL(latitude: station.lat, longitude: station.lng)
|
let url = SiriCheapestLookup.mapsURL(latitude: station.lat, longitude: station.lng)
|
||||||
return .result(opensIntent: OpenURLIntent(url))
|
return .result(
|
||||||
|
opensIntent: OpenURLIntent(url),
|
||||||
|
dialog: IntentDialog(stringLiteral: "Opening Maps to \(station.name), \(distanceText) away.")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user