In a native iOS app, how does a universal link differ from a custom URL scheme link in how iOS verifies, routes and delivers it?
answer
- who proves the link belongs to you
- a website file versus an Info.plist entry
- what opens when the app is missing
- NSUserActivity versus UIOpenURLContext
- two apps claiming one scheme
basics
~20 sA universal link is an ordinary https URL that iOS opens in the app only after the domain's apple-app-site-association file confirms the app, falling back to the browser otherwise. A custom scheme is unverified, and any app can register it.
solid answer
~40 sA universal link is a normal `https` URL. The app lists the host as `applinks:zoo.example.com` in its Associated Domains entitlement, the site serves an `apple-app-site-association` file naming the app, and iOS checks that pair after install; without the app, the same URL opens in the browser. In a scene-based app it arrives as an `NSUserActivity` of type `NSUserActivityTypeBrowsingWeb`, URL in `webpageURL`, through `scene(_:continue:)`. A custom scheme such as `zooapp://` is declared under `CFBundleURLTypes` in Info.plist; nothing verifies it, another app can register the same scheme (Apple says the target is then undefined), and no web page stands behind it. It arrives as a `UIOpenURLContext` through `scene(_:openURLContexts:)`. Apple calls schemes acceptable but strongly recommends universal links, and both need their parameters validated.
code
plist · 14 lines<!-- Info.plist: the zooapp:// custom scheme -->
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.example.zoo</string>
<key>CFBundleURLSchemes</key>
<array>
<string>zooapp</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>go deeper
Recall the two registrations: the applinks: entitlement plus the site's apple-app-site-association file for universal links, CFBundleURLTypes for a scheme, and that only the first is verified.
Explain the delivery shapes: an NSUserActivity of type NSUserActivityTypeBrowsingWeb for a universal link, a UIOpenURLContext for a scheme, and the scene callbacks each reaches.
Show why verification protects the domain but not the parameters, why a duplicated scheme has an undefined target, and why the app opening its own universal link stays out of the app.
Frame the rule a team sets: universal links for anything shared or emailed, a scheme only where both ends are controlled, and the same input validation on both paths.
## Two ways a link reaches an iOS app An iOS app can be opened from a link in two ways. A **universal link** is a standard `https` URL on a website you control, such as `https://zoo.example.com/animals/red-panda`. A **custom URL scheme** link uses a scheme you invent and register, such as `zooapp://animals/red-panda`. Both can take a person straight to a screen, but iOS registers, verifies and delivers them differently, and those differences are what an interviewer is probing. ## How a universal link is set up and verified A universal link rests on a **two-way association** between the app and the website: - The app's **Associated Domains entitlement** (`com.apple.developer.associated-domains`) lists the host with the `applinks:` service prefix, for example `applinks:zoo.example.com`. You add it in Xcode's Signing & Capabilities tab; an entry names a host (optionally with an alternate mode such as `?mode=developer`), never a path or a trailing slash. - The website serves an **`apple-app-site-association`** file (no extension) at `https://zoo.example.com/.well-known/apple-app-site-association`. Its `applinks` section names the app as `<Application Identifier Prefix>.<Bundle Identifier>`, for example `ABCDE12345.com.example.zoo`, and lists which URL patterns the app handles. - When someone installs the app, the system attempts to download that file and verify the domains in the entitlement. Since iOS 14 the request goes to an **Apple-managed content delivery network** dedicated to associated domains rather than straight to your server. Only the site's owner can put that file on the domain, so an unrelated app cannot claim the link. If the app isn't installed, the system opens the same URL in the person's default browser and the website handles it: one URL serves both. ## How a custom scheme is registered A custom scheme is declared in Info.plist under **`CFBundleURLTypes`**. Each entry carries `CFBundleURLSchemes` (the scheme strings), `CFBundleURLName` (an identifier, conventionally reverse DNS) and `CFBundleTypeRole` (Editor for a scheme you define, Viewer for one you adopt). No server is consulted. Apple's documentation spells out the consequences: - A reverse-DNS identifier is good practice but does not stop other apps registering the same scheme. - If several apps register one scheme, which app the system targets is **undefined**, and there is no mechanism to change it. - Custom schemes are an acceptable form of deep linking, but universal links are strongly recommended. A scheme URL also has no website behind it, so when no app claims it there is no web page to fall back to. ## How each one is delivered | | Universal link | Custom scheme | |---|---|---| | Registered in | Associated Domains entitlement and the site's AASA file | `CFBundleURLTypes` in Info.plist | | Verified by | iOS, against the domain's file | nothing | | App not installed | opens in the default browser | no web page behind it | | Arrives in a scene-based app as | `NSUserActivity`, type `NSUserActivityTypeBrowsingWeb`, URL in `webpageURL` | `UIOpenURLContext` with `url` and `options` | | Running app | `scene(_:continue:)` | `scene(_:openURLContexts:)` | | Cold launch | `connectionOptions.userActivities` | `connectionOptions.urlContexts` | | SwiftUI | `onOpenURL(perform:)`, as a plain URL | `onOpenURL(perform:)` | Apps that have not adopted scenes receive the two kinds in `application(_:continue:restorationHandler:)` and `application(_:open:options:)` on the app delegate. Both of those methods are **deprecated as of iOS 26**, in favour of the scene lifecycle. One more delivery rule matters in practice: if your own app opens a universal link to your website with `UIApplication`'s `open(_:options:completionHandler:)` or SwiftUI's `openURL`, Apple says the link won't open in your app. Inside the app, route the URL yourself. ## Treat both as untrusted input Apple warns that universal links and URL schemes are both an attack vector into the app: 1. Validate every URL parameter and discard malformed URLs. 2. Limit what a link can do: never let a link delete content or expose sensitive information directly. 3. Include improperly formatted URLs in your URL-handling tests. Verification proves that the *domain* belongs to you; it says nothing about who crafted the query string, so a universal link deserves the same checks as a scheme URL. ## In the zoo app Animal-page links shared from the zoo's website are universal links, so they open the app's animal screen when the app is installed and the web page otherwise. The ticket emails also carry a `zooapp://tickets/...` fallback link: it works only where the app is installed, it could in principle be claimed by another app, and the app parses it with `URLComponents` and checks every value before acting on it.
- Why doesn't calling UIApplication.shared.open with the zoo's own universal link, from inside the zoo app, open the animal screen?Apple's documentation says that when your app opens a universal link to your own website with `open(_:options:completionHandler:)` or SwiftUI's `openURL`, the link won't open in your app. The system treats it as the app sending the person out. Inside the app, pass the URL to your own routing code instead of handing it back to the system.
- In a custom-scheme handler, what does UISceneOpenURLOptions' sourceApplication tell you, and can you trust the sender with it?`sourceApplication` is the bundle ID of the app that opened the URL, but UIKit fills it only when that app shares your team identifier; from another developer's app it is `nil`. It is no general authentication: anything could have sent the URL, so validate its contents and limit what it can trigger.
A universal link is a street address the land registry has confirmed belongs to the tenant: post goes to their flat if they live there, otherwise to the building's front desk (the website). A custom scheme is a nickname written on an envelope; anyone can answer to it.
- Universal links use a special applinks:// URL scheme inside the app.
- A unique reverse-DNS CFBundleURLName keeps other apps off our scheme.
- Without the app installed, a universal link shows an error page.
- Universal link parameters come from our own site, so they need no validation.
- Every app receives both link kinds in application(_:open:options:).