Widget links maps:// directly so CarPlay can route to Apple Maps

- The widget now uses the native maps://?daddr= scheme for taps in both
  sizes. In CarPlay there is no containing app to relay through, but since
  Apple Maps IS a CarPlay app, the system may route the tap straight to
  Maps on the car display (WWDC25: widgets can launch apps in CarPlay).
- iOS keeps working via onOpenURL: the app now forwards maps:// URLs (if
  the Home Screen delivers them to the app), plus legacy fuelboard:// and
  http://maps.apple.com links from older cached timelines.
- No public API exists for a widget to detect CarPlay context, so the
  single maps:// link serves both; the app-side forward is the iOS safety
  net. 35 tests pass.
This commit is contained in:
FuelBoard Contributor
2026-08-12 13:07:44 +01:00
parent 1ff14607c5
commit 3e226ece57
3 changed files with 44 additions and 20 deletions
+8 -4
View File
@@ -5,9 +5,13 @@ import AppIntents
// FuelBoard widget petrol stations near you.
// systemMedium: top 3-4 stations with price + distance, each row opens Maps
// systemSmall: single station, whole widget opens Maps
// Taps deep-link to Apple Maps directions (maps://?daddr=).
// Note: on the home screen Link opens Maps directly. Inside CarPlay the widget
// renders but can't launch Maps (widgets can only launch their own CarPlay app).
// Taps deep-link to Apple Maps directions (maps://?daddr=). The widget uses
// the native Maps scheme (not a custom app scheme) so that CarPlay can route
// the tap straight to Apple Maps which IS a CarPlay app without needing
// the containing app to launch. On the Home Screen the system either opens
// Maps directly or delivers the URL to FuelBoard, whose onOpenURL forwards it
// (and also still handles legacy fuelboard:// and http://maps.apple.com links
// from older cached timelines).
//
// Each widget instance is configured INDEPENDENTLY via its own App Intent
// (long-press Edit Widget): fuel type (Unleaded/Premium/Diesel) and sort
@@ -261,7 +265,7 @@ struct FuelPriceWidgetView: View {
.foregroundStyle(.secondary)
}
ForEach(entry.stations.prefix(3)) { station in
Link(destination: station.widgetDirectionsURL ?? URL(string: "fuelboard://")!) {
Link(destination: station.widgetDirectionsURL ?? URL(string: "maps://")!) {
HStack(spacing: 8) {
Text(station.name)
.font(.caption.weight(.semibold))