Sub topic 8
Setting Up iOS Universal Links
Assume you know basic Flutter navigation, can build an iOS app, and control an HTTPS domain. A Universal Link is an HTTPS URL that iOS opens directly in your app when the domain has verified the app. Unlike a custom URL scheme, such as myapp://products/42, it still works as a normal web URL when the app is not installed.
The setup has three parts:
- Add the Associated Domains capability to the iOS app.
- Publish an
apple-app-site-associationfile on your domain. - Map the received path to a Flutter route.
Add the Associated Domains entitlement
Open the iOS project in Xcode:
- Open
ios/Runner.xcworkspace. - Select the Runner target.
- Open Signing & Capabilities.
- Add Associated Domains.
- Add this domain entry:
applinks:example.comThe entry is stored in the app's entitlements file. It should look similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:example.com</string>
</array>
</dict>
</plist>Use the real domain, without https:// and without a path. The app's provisioning profile must include this capability.
Publish the association file
Create this file at:
https://example.com/.well-known/apple-app-site-associationThe file has no .json extension. Serve it over HTTPS with an application/json content type.
Replace TEAMID with the Apple Developer Team ID and use the bundle identifier from Xcode:
{
"applinks": {
"details": [
{
"appIDs": ["TEAMID.com.example.app"],
"components": [
{ "/": "/products/*" }
]
}
]
}
}The components entry allows URLs such as /products/42. A path outside the listed patterns remains a web link. You can add more components when the app should handle additional paths.
The Team ID is not necessarily the same value as the visible organization name. Find it in the Apple Developer account or in the app's signing configuration.
Connect the URL to Flutter
Universal Link verification only decides whether iOS opens the app. Your Flutter router still needs a matching route, such as /products/:id. With go_router, the route can read the path parameter and display the product screen.
Test on a real device or simulator after installing a signed build. iOS may cache association results, so changing the file might require reinstalling the app.
Exercise
Why can a correct Flutter route still open Safari instead of the app?
Show answer
iOS opens Safari when domain verification fails, the URL path is not allowed by apple-app-site-association, or the installed build lacks the matching Associated Domains entitlement.