skip to content

A zoo app's shared links to animal pages open in Safari instead of the iOS app; what makes iOS skip the app, and how do you find the cause?

level: seniorimportance: should knowfreq 55%

answer

  1. was it really a universal-link tap
  2. same domain, already in Safari
  3. entitlement host and the file's appIDs
  4. https, valid certificate, no redirects
  5. CDN copy: 24 hours, weekly device check

basics

~20 s

iOS skips the app when a tap isn't treated as a universal link (same-domain tap in Safari, the app opening its own link) or verification fails: missing entitlement host, a redirected, wrong or unmatched apple-app-site-association file, or an outdated device copy.

solid answer

~40 s

I'd split it in two. First, was it a universal-link tap at all? Apple keeps a same-domain tap inside Safari in Safari, and a universal link the app opens itself with `UIApplication`'s `open(_:options:completionHandler:)` or SwiftUI's `openURL` won't open in that app. Second, did the association verify and match? Check that the signed build's Associated Domains entitlement has `applinks:` for the exact host, with `www` and each subdomain listed separately; that every host serves `/.well-known/apple-app-site-association` over HTTPS with a valid certificate and no redirects; that `appIDs` hold team prefix plus bundle ID; and that the path isn't caught by an earlier `exclude`. Finally, timing: devices fetch the file via Apple's CDN, which requests it within 24 hours, and recheck about weekly, so a fix lands slowly. For a private staging host, use `?mode=developer`.

code

plist · 7 lines
plist
<!-- Zoo.entitlements (Debug): a staging host the public CDN can't reach -->
<key>com.apple.developer.associated-domains</key>
<array>
  <string>applinks:zoo.example.com</string>
  <string>applinks:www.zoo.example.com</string>
  <string>applinks:staging.zoo.example.com?mode=developer</string>
</array>

go deeper

for a junior

Recall that a universal link falls back to the web silently and that both the entitlement and the site's file must be right.

for a middle

Explain the hosting rules: /.well-known path, HTTPS with a valid certificate, no redirects, one entry and one file per host, appIDs with the team prefix.

for a senior

Separate taps iOS deliberately keeps in Safari from verification failures, walk components in order, and account for the CDN's 24-hour fetch and weekly device checks.

for a principal

Put the AASA file and the entitlement under one owner with a release checklist, and give staging hosts developer mode so testing never depends on the CDN.

## Two questions before any fix When a link to `https://zoo.example.com/animals/red-panda` opens Safari instead of the zoo app, there are two separate questions: 1. Did iOS treat this tap as a universal link at all? 2. If so, did it verify the app-to-domain association and find a pattern that sends this URL to the app? The causes cluster under those two questions, plus a third issue: timing. ## When a tap is not handled as a universal link Apple documents two cases where the system deliberately leaves a valid universal link in the browser or out of the app: - **A same-domain tap in Safari.** When someone is browsing `zoo.example.com` in Safari and taps a universal link on the same domain, the system opens it in Safari, respecting the likely intent to stay in the browser. Tapped from a page on a different domain, the same link opens the app. A tester who checks links by tapping them on the zoo's own website in Safari will keep seeing Safari. - **The app opening its own link.** If the zoo app calls `UIApplication`'s `open(_:options:completionHandler:)`, or SwiftUI's `openURL`, with a universal link to its own website, the link won't open in the app. A "View in app" button that hands the URL back to the system is a bug; route it internally. ## When the association fails Verification needs both halves, and a failure is silent: the URL simply behaves like an ordinary web link. | Check | What goes wrong | |---|---| | Associated Domains entitlement in the build you installed | the capability is missing, or the host is wrong | | Exact host | `applinks:zoo.example.com` does not cover `www.zoo.example.com`; each subdomain needs its own entry (or a `*.` prefix) and serves its own file | | Entitlement format | `<service>:<host>`, optionally `?mode=<alternate mode>`; no path, other query or trailing slash | | File location | must be `https://<host>/.well-known/apple-app-site-association`, no extension | | Transport | HTTPS with a valid certificate and **no redirects**, such as apex to `www` | | `appIDs` | `<Application Identifier Prefix>.<Bundle Identifier>`; a team prefix or bundle ID that differs from the installed build's fails | | `components` | the path isn't matched, a case rule differs, or an earlier `exclude` entry catches it first | Two matching details catch teams out. The components array is read in order and the first match wins, so an exclusion placed above a broad pattern can swallow a page you meant to open in the app. And any link whose fragment is caught by an exclusion, such as Apple's `#no_universal_links` example, deliberately stays on the web. ## When the device has not seen the fix Since iOS 14, devices do not fetch the file from your server. They ask an **Apple-managed CDN** for associated domains, which fetches from your server when it has no copy or an old one. Apple's documentation says: - The CDN requests your domain's file within 24 hours. - Devices check for updates approximately once per week after the app is installed. - At install time, the system attempts to download the file and verify the domains. So a corrected file, or one newly published after users installed the app, can take days to reach phones. A **staging server that the public internet can't reach** never verifies through the CDN at all; for development, add an alternate mode to the entitlement, `applinks:staging.zoo.example.com?mode=developer`. Apple limits developer mode to apps signed with a development profile on devices whose owners opt in, and allows any valid SSL certificate there, including one the system doesn't trust. ## A diagnosis order 1. Reproduce from another app, such as a link in Notes or Messages, not from the zoo's site in Safari and not from inside the zoo app. 2. Confirm the installed build carries the entitlement with every host the links use. 3. Fetch `/.well-known/apple-app-site-association` for each host and confirm a direct HTTPS response with a valid certificate, no redirect and valid JSON. 4. Compare `appIDs` with the build's team prefix and bundle ID. 5. Walk the failing URL through `components` top to bottom. 6. If the file changed recently, allow for the CDN and weekly device check; for private hosts, use `?mode=developer`. Turning the opened URL into the right screen is a separate problem; this checklist ends when the app receives the link.

  • The zoo app's own 'Open animal' button calls UIApplication.shared.open with https://zoo.example.com/animals/lion and lands in Safari; is the association broken?
    Not necessarily. Apple's documentation says that when an app opens a universal link to its own website with `open(_:options:completionHandler:)` or SwiftUI's `openURL`, the link won't open in that app. Test the association from another app, and make the button route inside the app instead.
  • Links on zoo.example.com open the app but links on www.zoo.example.com open Safari; what is missing?
    Associated domains are per host. Add `applinks:www.zoo.example.com` to the entitlement (or a `*.` prefix that matches subdomains) and make `www` serve its own `apple-app-site-association` file directly, since a redirect from `www` to the apex domain also fails verification.
  • Why does a link tapped on a zoo.example.com page in Safari stay in Safari when the same link from Mail opens the app?
    Apple documents that when a person browsing a site in Safari taps a universal link in the same domain, the system keeps it in Safari, respecting the likely intent to stay in the browser. A link in a different domain, or in another app, opens the app.

  • If one link opens the app, the whole domain's association must be correct.
  • Redirecting the AASA request from zoo.example.com to www is harmless.
  • Devices download the AASA file directly from our server on every tap.
  • A universal link tapped on our own site in Safari should open the app.
  • Putting /animals in the applinks: entitlement entry limits which paths open the app.