SwiftUI .onOpenURL not called every time when opening app from Widget using Link(destination:)

6 hours ago 1
ARTICLE AD BOX

I am opening my app from a Widget using a custom URL scheme. The app does open every time, but .onOpenURL is not called consistently — sometimes it fires, sometimes it does not.

Widget code

Link(destination: makeBMILink(entry: entry)) { resultView } .buttonStyle(.plain) func makeBMILink(entry: MyWidgetEntry) -> URL { var components = URLComponents() components.scheme = "myapp" components.host = "calcwidget" components.queryItems = [ URLQueryItem(name: "weidgetType", value: CalcConvertType.BMI.rawValue), URLQueryItem(name: "gender", value: entry.data?.bmiGender ?? ""), URLQueryItem(name: "weight", value: entry.data?.bmiWeight ?? "0"), URLQueryItem(name: "height", value: entry.data?.bmiHeight ?? "0"), URLQueryItem(name: "age", value: entry.data?.bmiAge ?? "0") ] return components.url! }

App side (SwiftUI)

.onOpenURL { url in if url.host == "calcwidget" { print("onOpenURL called:", url) // Handle widget deep link } }

Observed behavior

Tapping the widget always opens the app

But .onOpenURL:

✅ sometimes gets called

❌ sometimes does NOT get called

This happens especially when:

Opening the app from the widget repeatedly

App is already running in foreground/background

No crashes, no invalid URLs

What I’ve verified

URL scheme is registered correctly

Link(destination:) is used (not Button)

URL is valid (verified by logging)

.onOpenURL is attached to a visible SwiftUI view

The same URL sometimes works, sometimes doesn’t

Question

Why does .onOpenURL not fire every time when opening the app from a Widget using Link(destination:), even though the app opens successfully? Is this expected behavior in SwiftUI / WidgetKit, or am I missing something in state handling?

What I am looking for

Explanation of why .onOpenURL may not appear to fire

Whether repeated opening with the same URL affects delivery

Best practice to reliably handle widget deep links in SwiftUI

Read Entire Article