For MarketersFor DevelopersFor Product
11 min read

iOS Universal Links

A Universal Link is an ordinary https:// URL that iOS hands to your app instead of Safari, because your app and your website have both declared that they belong together. When the setup is right, a tap opens the app on the matching screen. When the app is not installed, the same URL loads your web page.

This guide is the reference for the mechanism itself: what iOS checks, where it gets the file from, and how to find out which part is broken. For a broader walkthrough of iOS deep linking, including deferred deep linking and SDK choices, see the iOS deep linking guide on our blog. For the difference between custom schemes and Universal Links, see Deep link vs Universal Link.

What you'll learn

  • The two halves of the association and how iOS checks them
  • Writing the apple-app-site-association (AASA) file in the current components format
  • How Apple's CDN changes when your file updates reach devices
  • A failure-by-failure troubleshooting checklist

How the association works

A Universal Link needs agreement between two places:

  1. Your app declares the domains it claims in the Associated Domains entitlement, for example applinks:links.example.com.
  2. Your domain serves an AASA file at https://links.example.com/.well-known/apple-app-site-association that names your app and the URL patterns it may open.

When someone installs your app, the system downloads the AASA file for each applinks domain and records which URLs your app may open. Later, when the user taps a link, iOS checks the URL against that stored record. Nothing is fetched at tap time, and your app code is not involved until the decision has been made. That is why most "it opens Safari" bugs are configuration problems rather than Swift bugs.

Key Concept

Since iOS 14, devices do not request the AASA file from your server. They get it from an Apple-managed CDN dedicated to associated domains (app-site-association.cdn-apple.com). If the CDN has an old copy, or none, it fetches the latest version from your server. Your server has to be reachable by Apple's CDN, not just by your phone.

The apple-app-site-association file

The file has no extension and lives at exactly:

https://<fully qualified domain>/.well-known/apple-app-site-association

Apple requires https:// with a valid certificate and no redirects. Serve it as application/json: Apple does not strictly require that content type, but some CDNs and proxies mishandle anything else.

The components format (iOS 13 and later)

Apple's current documentation uses appIDs (an array) and components (an array of matching rules):

{
  "applinks": {
    "details": [
      {
        "appIDs": ["ABCDE12345.com.example.app"],
        "components": [
          { "/": "/account/delete/*", "exclude": true, "comment": "Keep destructive pages on the web" },
          { "#": "no_universal_links", "exclude": true },
          { "/": "/product/*", "comment": "Product pages open the app" },
          { "/": "/help/*", "?": { "article": "?*" }, "comment": "Help links that carry an article ID" }
        ]
      }
    ]
  }
}

Each component can match three parts of the URL:

KeyMatchesDefault
/The path* (everything)
?The query string, or a dictionary of individual query items*
#The fragment*
excludeIf true, a match stops the URL from opening the appfalse
caseSensitiveWhether patterns are case sensitivetrue
percentEncodedWhether the URL is compared in its percent-encoded formtrue
commentIgnored by the system; use it to document intentnone

Rules that decide real-world behavior:

  • Order matters. iOS walks the array from top to bottom and the first match wins. Put exclude rules above the broad rules they carve out of, or they never run.
  • A component matches only if every key it sets matches. { "/": "/help/*", "?": { "article": "?*" } } does not match /help/ without an article parameter.
  • Wildcards: * matches zero or more characters, ? matches exactly one, and ?* matches one or more.
  • Case sensitivity is on by default. /Product/1 does not match "/product/*" unless you set "caseSensitive": false.
  • appIDs values are TEAMID.bundle.id. The prefix is your 10-character Team ID from the Apple Developer account, not an App Store ID.

The legacy paths format

Older files use a single appID string and a paths array, with NOT for exclusions:

{
  "applinks": {
    "apps": [],
    "details": [
      { "appID": "ABCDE12345.com.example.app", "paths": ["NOT /account/*", "/*"] }
    ]
  }
}

It still works, but it matches the path only, so you cannot route on query parameters or fragments. Apple's debugging technote (TN3155) asks you not to mix the two formats in one entry, because that can produce unexpected matching.

Try It

Paste your domain into the AASA validator. It fetches your file, checks HTTPS, redirects, content type, size, JSON structure and app ID format, compares your file with the copy on Apple's CDN, and tells you whether a given URL would open your app and which rule matched or excluded it.

The Associated Domains entitlement

In Xcode, open your target's Signing & Capabilities tab and add Associated Domains. Then add one entry per domain:

applinks:example.com
applinks:links.example.com
applinks:*.example.com

Details that cause silent failures:

  • Host only. No https://, no path, no trailing slash, and no port: applinks:example.com:8080 will not work.
  • Each subdomain is separate. applinks:www.example.com needs a file at https://www.example.com/.well-known/.... A file on example.com does not cover it.
  • Wildcards read the parent's file. applinks:*.example.com uses the file hosted at https://example.com/.well-known/apple-app-site-association, per Apple's TN3155.
  • Manual signing. With automatic signing, Xcode adds the capability to your App ID. With manual provisioning profiles, enable Associated Domains on the App ID in the developer portal and regenerate the profile, or the entitlement is not honored.

Developer mode for testing

Because devices read from Apple's CDN, a file on a staging server that the CDN cannot reach, or a change you made five minutes ago, will not show up on your phone. For development builds, append an alternate mode to the entitlement:

applinks:staging.example.com?mode=developer

With ?mode=developer, the device fetches the file directly from your server. It applies only to apps signed with a development profile, and only on devices where you have enabled it: turn on Developer Mode, then in Settings > Developer, under Universal Links, turn on Associated Domains Development. Builds signed for TestFlight or the App Store do not use developer-mode entries, so keep a plain applinks: entry for every production domain.

Handling the link in your app

iOS delivers a Universal Link as an NSUserActivity of type NSUserActivityTypeBrowsingWeb, with the URL in webpageURL. Where it arrives depends on your app's lifecycle:

App structureCold start (app not running)App already running
SwiftUI App.onOpenURL { url in ... }.onOpenURL
UIKit with scenesscene(_:willConnectTo:options:), in connectionOptions.userActivitiesscene(_:continue:)
UIKit without scenesapplication(_:continue:restorationHandler:)same

The most common app-side bug is implementing only the AppDelegate method in an app that uses scenes. The link opens the app, but nothing navigates, and only on a cold start.

// UIKit scene delegate: handle both entry points
func scene(_ scene: UIScene, willConnectTo session: UISceneSession,
           options connectionOptions: UIScene.ConnectionOptions) {
    if let activity = connectionOptions.userActivities.first(where: {
        $0.activityType == NSUserActivityTypeBrowsingWeb
    }), let url = activity.webpageURL {
        router.handle(url)
    }
}

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
    guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
          let url = userActivity.webpageURL else { return }
    router.handle(url)
}

Apple's guidance is to treat the URL as untrusted input: validate parameters, discard malformed URLs, and do not let a link trigger destructive actions directly.

SwiftUI

SwiftUI passes Universal Links to .onOpenURL as a plain URL. Use .onContinueUserActivity only for other activity types such as Handoff.

Flutter and React Native

In Flutter, use the app_links package or Flutter's built-in deep linking. Since Flutter 3.27, built-in deep linking is on by default, and Flutter's docs say apps using a plugin such as app_links must set FlutterDeepLinkingEnabled to NO in Info.plist. In React Native, read links with Linking.getInitialURL() and the url event; on iOS, wire the AppDelegate to RCTLinkingManager.

Ulinkly SDK

If you use the Ulinkly iOS, Flutter or React Native SDK, follow its setup guide for the delegate wiring. The entitlement still has to list your Ulinkly domain.

When AASA changes reach devices

Apple documents the timing as follows:

  • Apple's CDN requests the AASA file for your domain within 24 hours.
  • When the app is installed, the device downloads the file from the CDN right away.
  • After installation, devices check for updates approximately once per week.
  • There is no way to invalidate the CDN cache. To pick up a newer file on a test device, reinstall the app once the CDN has the new version.

So "I fixed the file but it still opens Safari" usually means the CDN or the device still holds the old version. Check what Apple has before changing anything else:

curl -s https://app-site-association.cdn-apple.com/a/v1/links.example.com

If that response differs from your origin file, wait for the CDN, or use ?mode=developer on a development build. The AASA validator runs this comparison for you.

Troubleshooting

Work through these in order. Each one names the symptom, the check, and the fix.

1. The file is not reachable as Apple sees it

Check: curl -v https://links.example.com/.well-known/apple-app-site-association. You want HTTP 200 and the JSON body, with no 301 or 302.

Common causes:

  • A redirect (apex to www, HTTP to HTTPS on the path itself, or a trailing-slash rewrite). Apple does not follow redirects for the file.
  • A 403 or 404 caused by a firewall, bot protection, geo-blocking or an IP allowlist. Apple's CDN does not publish its IP ranges, and TN3155 says the file must be reachable from any IP address and for any user agent. Test with curl -A "RandomAgent/1.0" to catch user-agent filtering.
  • A single-page app router or framework returning its HTML page for unknown paths.

2. The app ID does not match the build

Check: the appIDs (or appID) value against your Team ID and the bundle identifier of the build on the device. Projects that moved to a different developer account, or use a different bundle ID for debug builds, often fail here.

3. The URL does not match any rule

Check: test the exact URL in the validator, or on a Mac run Apple's built-in tool:

sudo swcutil dl -d links.example.com
sudo swcutil verify -d links.example.com -j ./aasa.json -u https://links.example.com/product/42

Look out for an exclude rule above your match, case sensitivity, and query-item rules that require a parameter your link does not carry.

4. The entitlement is wrong

Check: the entitlement in the signed build, not just the Xcode UI. Run codesign -d --entitlements - YourApp.app on the built app and confirm com.apple.developer.associated-domains lists the right hosts. Typos, a missing subdomain, or a profile without the capability all end up here.

5. The device has stale data or a user choice

Check on the device: in Settings > Developer > Universal Links > Diagnostics, enter the full URL. It reports whether the link is valid for an installed app.

If a user once picked "Open in Safari" from the long-press menu, iOS remembers that choice for the domain. Long-press the link in Notes and choose "Open in [your app]" to reset it.

6. It works from Notes but not from somewhere else

That is usually expected behavior, not a bug:

  • Typed or pasted into Safari's address bar: never opens the app. That is direct navigation in the browser.
  • Same-domain taps: when the user is already on your site in Safari and taps a Universal Link on the same domain, iOS keeps them in Safari. Use a different subdomain for links that should leave the browser.
  • Your own app calling open(_:) on a Universal Link to your own domain will not open your app.
  • Third-party browsers decide for themselves whether to support Universal Links.
  • Social in-app browsers. Instagram, TikTok and Facebook open links in their own WebView, which honours a Universal Link only for a real link tap; a redirect into one will not open your app. Breaking out needs a tappable screen on a different host, because iOS also suppresses the handoff when the link points at the host you are already on.

For a quick real-device test of any of these, the deep link tester gives you a QR code so you can open a page on your phone and tap the link there, rather than pasting it.

Gotcha

Do your final testing on a physical device with a build installed the way users will install it. TestFlight and App Store builds read the AASA from Apple's CDN, so a link that works in a development build with ?mode=developer can still fail in production if the CDN cannot fetch your file.

How Ulinkly handles this

For every domain registered in your project, both your-subdomain.shared.ly and custom domains you add under Domains, Ulinkly generates and serves the AASA file at /.well-known/apple-app-site-association, built from the Bundle ID and Team ID you enter under Configuration > iOS. The file is served directly, with no redirect and as application/json. It uses the legacy appID and paths format, claiming all paths on your link domain apart from a few reserved ones, which iOS fully supports.

You still have to:

  1. Add applinks:your-subdomain.shared.ly (or your custom domain) to the app's Associated Domains entitlement.
  2. Make sure the Team ID and Bundle Identifier in the dashboard match the build you ship.
  3. Allow for Apple's CDN delay after you change the iOS configuration.

The ulink verify command in the Ulinkly CLI checks the entitlement, bundle ID, Team ID and the served AASA file from your project directory.

Frequently asked questions

Do Universal Links work when the app is not installed?

The URL opens in the default browser and loads your web page. What happens next depends on that page. A link service can then send the user to the App Store or a web fallback; routing a new user to specific content after install is deferred deep linking, a separate layer covered in Deferred deep links (in Ulinkly, deferred deep linking is part of the paid plans, Starter and up).

Why does my Universal Link work in a development build but not from TestFlight?

Most often the development build uses ?mode=developer and reads your server directly, while TestFlight reads Apple's CDN, which may have an old copy or no copy if it cannot reach your server. Compare the CDN copy with your origin file.

Can I use a custom URL scheme as well?

Yes. Many apps keep a custom scheme for app-to-app calls or as a fallback. Universal Links are the better choice for links people share, since a scheme does nothing when the app is missing and other apps can claim the same scheme. Our post on URI scheme security covers the hijacking risk.

How do I stop specific URLs from opening the app?

Add a component with "exclude": true above your broader rules, for example for password-reset or payment pages that must stay on the web. In the legacy format, prefix the path with NOT .

Quick recap

  • Universal Links need a matching entitlement and AASA file; a mismatch silently falls back to Safari.
  • Prefer the components format for new files; order matters and the first match wins.
  • Since iOS 14 devices read the file from Apple's CDN, which picks up changes within 24 hours; use ?mode=developer while testing.
  • Diagnose in order: reachability, app ID, URL matching, entitlement, device state, then context such as typed URLs and in-app browsers.