Post

Replies

Boosts

Views

Activity

Reply to SwiftUI apps in macOS are not triggering onOpenURL when receiving a Universal Link
This question was posted a long time ago but, as I encountered the same problem on my universal app (i.e the universal link works perfectly on iPhone and iPad but the .onOpenURL was not called on macOS) and found a solution, I thought it could be useful to others. Basically, for macOS, I use the .onContinueUserActivity modifier instead of .onOpenURL and everything works like a charm: #if os(iOS)       .onOpenURL { url in         handle(universalLink: url)       } #elseif os(macOS)       .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { userActivity in         guard let url = userActivity.webpageURL else { return }         // Do the same handling than in .onOpenURL         handle(universalLink: url)       } #endif One drawback is that you need some conditional building using preprocessor macros for iOS and macOS but it's something I can live with as this solution does not add too much noise to my code. Hope it helps.
Aug ’22