iOS Universal Links配置:排除裸域名,仅带路径链接唤起应用
Can This Universal Links Setup Be Achieved?
Absolutely, this is totally doable with iOS Universal Links! Let me walk you through exactly how to configure everything to match your needs:
1. Configure the apple-app-site-association File
This is the backbone of Universal Links. You'll need to define path rules that exclude the root domain but include all other paths. Here's what the file should look like:
{ "applinks": { "apps": [], "details": [ { "appID": "YOUR_TEAM_ID.YOUR_BUNDLE_ID", "paths": [ "NOT /", "/*" ] } ] } }
NOT /: This rule tells iOS that the root URL (mydomain.com/) should not trigger your app—so it'll always open in Safari instead./*: This catches all other paths (likemydomain.com/sometext,mydomain.com/anotherpath, etc.) and tells iOS to attempt to open your app if it's installed.
2. iOS App Configuration
- Open your Xcode project, go to your target's Signing & Capabilities tab.
- Add the Associated Domains capability, then add a domain entry in the format:
applinks:mydomain.com(replace with your actual domain). - Double-check that your Team ID and Bundle ID in the
apple-app-site-associationfile match exactly what's in Xcode.
3. Web Server & Fallback Handling
- Host the
apple-app-site-associationfile at eitherhttps://mydomain.com/apple-app-site-associationorhttps://mydomain.com/.well-known/apple-app-site-association. Make sure the file has no file extension and that your server returns it with aContent-Type: application/jsonheader. - For paths that should open the app (if installed), set up a fallback on your web server: if iOS doesn't launch the app (meaning it's not installed), the link should load the corresponding web page content instead. Most server-side frameworks or static site hosts let you handle this easily.
Quick Testing Tips
- Test on a real iOS device (simulators can have inconsistent Universal Links behavior).
- Avoid tapping links directly in Messages or Mail during initial testing—use a Notes app link or a web page link instead, since some apps override link handling.
- You can use Apple's built-in validation tool to verify your
apple-app-site-associationfile is set up correctly.
内容的提问来源于stack exchange,提问作者Baldoph




