# SwiftUI deep linking and Universal Links

> How to handle deep links and Universal Links in a SwiftUI app with onOpenURL, onContinueUserActivity and NavigationStack, how the Strait Swift SDK delivers short links and deferred links, and how to test with associated domains in developer mode.

Source: https://straitlink.in/guides/swiftui-deep-linking/
Markdown: https://straitlink.in/guides/swiftui-deep-linking.md

- [Guides](https://straitlink.in/guides/)
- SwiftUI

# 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](https://straitlink.in/ai/#prompt-ios)

STEPS · 4

- [1Two entry points, one router](https://straitlink.in/guides/swiftui-deep-linking/#two-entry-points-one-router)
- [2Cold launches](https://straitlink.in/guides/swiftui-deep-linking/#cold-launches)
- [3Associated domains, and testing them](https://straitlink.in/guides/swiftui-deep-linking/#associated-domains-and-testing-them)
- [4After an App Store install](https://straitlink.in/guides/swiftui-deep-linking/#after-an-app-store-install)

**Step 1 of 4**Two entry points, one router

AT A GLANCE · SWIFTUI

- Builds on : `StraitSDK`

- Platforms : iPhone and iPad

- Start in the docs : [iOS (Swift) SDK](https://straitlink.in/docs/sdks/ios/)

- Free plan : 25,000 taps a month, no card

## 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](https://straitlink.in/docs/sdks/ios/), 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.

[Open the SwiftUI docs](https://straitlink.in/docs/sdks/ios/)

Docs for this setup

## Where to go next for SwiftUI

- [iOS (Swift) SDK Install, the client, scenes and SwiftUI](https://straitlink.in/docs/sdks/ios/)
- [How iPhone install matching works What is used, the off-switch, the privacy label](https://straitlink.in/docs/iphone-install-matching/)
- [App Links & Universal Links The verification behind a direct open](https://straitlink.in/docs/app-links/)

Check your setup

## Free tools for the parts that usually break

- [Will it open my app? Simulate a tap from WhatsApp, Instagram or Chrome](https://straitlink.in/tools/will-it-open/)
- [assetlinks.json checker Is your Android App Links file right?](https://straitlink.in/tools/assetlinks-checker/)
- [AASA validator Is your apple-app-site-association file right?](https://straitlink.in/tools/aasa-validator/)
- [Troubleshooting When a link opens the browser instead of the app](https://straitlink.in/docs/troubleshooting/)

Other guides: [Expo](https://straitlink.in/guides/expo-deep-linking/) · [Next.js](https://straitlink.in/guides/nextjs-deep-linking/) · [FlutterFlow](https://straitlink.in/guides/flutterflow-deep-linking/) · [Capacitor and Ionic](https://straitlink.in/guides/capacitor-deep-linking/) · [Jetpack Compose (Kotlin)](https://straitlink.in/guides/jetpack-compose-deep-linking/) · [Unity](https://straitlink.in/guides/unity-deep-linking/)

## Ship links that open your SwiftUI app.

Free for 25,000 taps a month, no card. Every tap gets a trace you can read.

[Start free](https://app.straitlink.in/?signup=1) [Read the quick start](https://straitlink.in/docs/quick-start/)
