Deep links and Universal Links in SwiftUI
SwiftUI hands you links through onOpenURL and onContinueUserActivity. Turning them into a NavigationStack path, and catching the link after an App Store install, takes a small router. Universal Links were tested on a real iPhone in October 2026.
- Guide
- iPhone and iPad
StraitSDK- Faster: one prompt
Two entry points, one router
SwiftUI delivers links in two ways. A custom-scheme URL, yourapp://…, which is how a browser hands a link to your app, arrives in .onOpenURL. A Universal Link on your verified domain arrives as an NSUserActivity in .onContinueUserActivity(NSUserActivityTypeBrowsingWeb). Both have to reach the same code, and so does the link the SDK finds on the first launch after an App Store install, which comes with no URL at all.
Pass both to the SDK and let its onLink callback be the one place that navigates:
import SwiftUI
import StraitSDK
struct Product: Hashable { let id: String }
final class LinkRouter: ObservableObject {
@Published var path = NavigationPath()
init() {
links.onLink { [weak self] event in // main queue; replays past events
guard event.matched, let p = event.path else { return }
if p.hasPrefix("/product/") { self?.path.append(Product(id: String(p.dropFirst(9)))) }
}
}
}
@main struct ShopApp: App {
@StateObject private var router = LinkRouter()
init() { links.start() }
var body: some Scene {
WindowGroup {
NavigationStack(path: $router.path) {
HomeView().navigationDestination(for: Product.self) { ProductView(id: $0.id) }
}
.onOpenURL { links.handle(url: $0) }
.onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { links.handle(userActivity: $0) }
}
}
}links is the client from the iOS SDK page, created once with your publishable key and link domain.
Cold launches
SwiftUI delivers the URL that launched the app through onOpenURL too, so the SDK labels that open by app state instead of closed. If you need the closed label, add a scene delegate and pass the launch URL to start(initialURL:), as the iOS page shows. Routing works the same either way.
Associated domains, and testing them
Add Associated Domains with applinks:hilltop.strait.link and save your Team ID and bundle ID in Dashboard → Apps & stores, so the link domain serves a matching apple-app-site-association. iOS fetches that file through Apple's CDN, which can lag behind changes. During development, applinks:hilltop.strait.link?mode=developer makes a device in developer mode fetch it directly.
Test the custom scheme with xcrun simctl openurl booted "yourapp://shop.example.com/product/42". Test Universal Links on a device by tapping the link in Notes or Messages: typing it into Safari's address bar doesn't trigger them, and neither does a tap inside Instagram's or Facebook's browser, where the link server shows its "open in Safari" page instead.
After an App Store install
When someone without your app taps a link in Safari, they see a Get the app page. Tapping it saves a coarse, short-lived device match and opens the App Store. On the first launch, start() checks it once and, if exactly one recent tap fits, onLink fires with that link's path. This is device matching, which you switch on in Dashboard → Settings → iPhone installs (new workspaces start with it off); on its own it never reads the clipboard, so iOS shows no paste prompt. This part hasn't been proven on a real iPhone yet, so keep a sensible fallback screen for launch-critical flows.
Docs for this setup
Where to go next for SwiftUI
Check your setup
Free tools for the parts that usually break
Other guides: Expo · Next.js · FlutterFlow · Capacitor and Ionic · Jetpack Compose (Kotlin) · Unity
Ship links that open your SwiftUI app.
Free for 25,000 taps a month, no card. Every tap gets a trace you can read.