Validating Universal Links involves several steps to ensure they are set up correctly and function as expected on iOS devices. Here’s a detailed guide:
1. Create the Apple App Site Association File
The Apple App Site Association (AASA) file is a JSON file that tells iOS which URLs your app can handle.
- Create the AASA File:
{
"applinks": {
"apps": [],
"details": [
{
"appIDs": ["<YOUR_TEAM_ID>.<YOUR_BUNDLE_ID>"],
"components": [
{
"/": "/<path-to-handle>",
"comment": "Matches any URL with the specified path."
}
]
}
]
}
}
1. Host the AASA File:
- Place the
apple-app-site-association
file at the root of your domain or in the.well-known
directory. - Ensure it’s served over HTTPS and with the correct content type (
application/json
).
2. Update App Capabilities
- Enable Associated Domains:
- Go to your Xcode project settings.
- Select your target and then the Capabilities tab.
- Turn on “Associated Domains” and add your domain with the
applinks:
prefix (e.g.,applinks:example.com
).
3. Handle Universal Links in Your App
- Implement the
application(_:continue:restorationHandler:)
Method:- Implement this method in your
AppDelegate
to handle the incoming universal link.
- Implement this method in your
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
if let url = userActivity.webpageURL {
// Handle the URL accordingly
return true
}
}
return false
}
4. Validate
Verify if apple-app-site-association
file is returned is valid, accessible though public https query and formatted correctly. Use this tool to validate: https://impute.pro/applinks-validator/
5. Test Your Universal Links
- Use a Real Device:
- Universal Links do not work in the iOS Simulator.
- Use a physical device to test.
- Install the App:
- Ensure the latest version of your app is installed on your test device.
- Open Links:
- Use the Notes app, Messages, or Safari to test the links.
- When you tap the link, it should open your app if it’s installed.
6. Debugging Universal Links
- Verify the AASA File:
- Use online tools like Apple’s AASA validator to ensure your file is correctly configured.
- Check the response headers to confirm the file is being served correctly.
- Check Device Logs:
- Use the Console app on macOS or Xcode to view device logs for any errors related to universal links.
- Use the
NSUserActivity
Debugging Tools:- Utilize the debugging tools in Xcode to inspect the
NSUserActivity
objects and ensure they contain the expected URL data.
- Utilize the debugging tools in Xcode to inspect the
7. Common Issues and Troubleshooting
- AASA File Issues:
- Ensure the AASA file is accessible and correctly formatted.
- Double-check the
appIDs
andcomponents
sections.
- Incorrect Associated Domains:
- Ensure the domain in the Associated Domains capability matches exactly.
- HTTPS Requirements:
- The AASA file must be served over HTTPS without any redirects.
By following these steps, you can ensure your Universal Links are correctly validated and functioning as intended. If you encounter issues, use the debugging steps to identify and resolve problems efficiently.