How to validate Universal Links

How to validate Universal Links

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.

  1. 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:

  1. Place the apple-app-site-association file at the root of your domain or in the .well-known directory.
  2. Ensure it’s served over HTTPS and with the correct content type (application/json).

2. Update App Capabilities

  1. 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

  1. Implement the application(_:continue:restorationHandler:) Method:
    • Implement this method in your AppDelegate to handle the incoming universal link.
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

  1. Use a Real Device:
    • Universal Links do not work in the iOS Simulator.
    • Use a physical device to test.
  2. Install the App:
    • Ensure the latest version of your app is installed on your test device.
  3. 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

  1. 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.
  2. Check Device Logs:
    • Use the Console app on macOS or Xcode to view device logs for any errors related to universal links.
  3. Use the NSUserActivity Debugging Tools:
    • Utilize the debugging tools in Xcode to inspect the NSUserActivity objects and ensure they contain the expected URL data.

7. Common Issues and Troubleshooting

  1. AASA File Issues:
    • Ensure the AASA file is accessible and correctly formatted.
    • Double-check the appIDs and components sections.
  2. Incorrect Associated Domains:
    • Ensure the domain in the Associated Domains capability matches exactly.
  3. 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.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *