To enable Universal Links on iOS and App Links on Android, you need to host two specific JSON files on your web server:
apple-app-site-association(AASA) for iOS: This file tells iOS which paths on your website should be handled by your iOS app.assetlinks.jsonfor Android: This file tells Android which paths on your website should be handled by your Android app.
Serving these files correctly is crucial for deep linking to work seamlessly.
1. Hosting the apple-app-site-association (AASA) File for iOS
-
File Content: The AASA file is a JSON file that maps your website's paths to your app. A common structure looks like this:
json { "applinks": { "apps": [], "details": [ { "appID": "TEAM_ID.com.yourcompany.yourapp", "paths": [ "/app/*", "/links/to/content/*", "*" ] } ] } }* ReplaceTEAM_ID.com.yourcompany.yourappwith your app's unique identifier (Team ID followed by your app's bundle ID). * Thepathsarray specifies which URL paths on your website should be handled by the app."*"means all paths. -
Hosting Requirements:
- Location: The file must be hosted at the root of your domain or in the
.well-knowndirectory. For example:https://yourdomain.com/.well-known/apple-app-site-associationhttps://yourdomain.com/apple-app-site-association(less common now)
- HTTPS: The file must be served over HTTPS.
- MIME Type: The
Content-Typeheader should beapplication/jsonorapplication/json; charset=utf-8. - No Redirects: The AASA file itself should not be redirected.
- Location: The file must be hosted at the root of your domain or in the
-
Verification: iOS devices download this file when your app is installed. You can test its accessibility using the Apple Validation Tool or by simply trying to access the URL in Safari.
2. Hosting the assetlinks.json File for Android
-
File Content: The
assetlinks.jsonfile contains information about your app and the website it's associated with.json [ { "relation": [ "delegate_permission/common.handle_all_urls" ], "target": { "namespace": "android.app", "package_name": "com.yourcompany.yourapp", "sha256_cert_fingerprints": [ "YOUR_APP_SHA256_FINGERPRINT" ] } } ]* Replacecom.yourcompany.yourappwith your app's package name. * ReplaceYOUR_APP_SHA256_FINGERPRINTwith the SHA256 fingerprint of your app's signing certificate (you can get this from your keystore or build tools). -
Hosting Requirements:
- Location: The file must be hosted at
https://yourdomain.com/.well-known/assetlinks.json. The.well-knownpath is mandatory. - HTTPS: The file must be served over HTTPS.
- MIME Type: The
Content-Typeheader should beapplication/jsonorapplication/json; charset=utf-8.
- Location: The file must be hosted at
-
Verification: Android devices check this file to verify the association. You can use the Google Asset Link API Validator to check your
assetlinks.jsonfile.
3. Server Configuration Best Practices
- Static File Serving: Configure your web server (e.g., Nginx, Apache, or your cloud provider's static hosting service) to serve these JSON files directly.
- Caching: Be cautious with caching these files. While caching can improve performance, it can also delay the propagation of changes if you update your app or website association. It's often recommended to set a short cache duration or disable caching for these specific files.
- Content Type: Ensure the correct
Content-Typeheader is set. - Accessibility: Make sure these files are publicly accessible without requiring authentication.
By correctly hosting these association files, you enable Universal Links and App Links, providing a smoother and more integrated experience for your users.