import SwiftUI @main struct FuelBoardApp: App { var body: some Scene { WindowGroup { ContentView() .onOpenURL(perform: handleOpenURL) } } /// WidgetKit widgets can only open their containing app, so a widget tap /// delivers a `fuelboard://directions?lat=..&lng=..` URL here instead of /// opening Apple Maps itself. Forward it to the native Maps directions /// URL (`maps://?daddr=`), which is what the app's own rows use. private func handleOpenURL(_ url: URL) { guard url.scheme == "fuelboard", url.host == "directions", let components = URLComponents(url: url, resolvingAgainstBaseURL: false), let lat = components.queryItems?.first(where: { $0.name == "lat" })?.value.flatMap(Double.init), let lng = components.queryItems?.first(where: { $0.name == "lng" })?.value.flatMap(Double.init), let mapsURL = URL(string: "maps://?daddr=\(lat),\(lng)&t=d") else { return } UIApplication.shared.open(mapsURL) } }