Dev.to WebDev 🛠 Dev 👁 0 📖 15 min read

Your Deep Link Opens Safari, Not Your App: Testing Universal Links and Android App Links Through a Tunnel

You tap a link in Notes or a chat app and expect your app to open on the product screen. Instead, Safari loads your website, or Android shows a chooser dialog. The code is fine and the route handler is fine, yet the link

You tap a link in Notes or a chat app and expect your app to open on the product screen. Instead, Safari loads your website, or Android shows a chooser dialog. The code is fine and the route handler is fine, yet the link still ends up in the browser.

This is one of the most frustrating bugs in mobile development because the failure happens before your code runs. The operating system decides whether your app owns that URL, and it makes that decision using files hosted on a domain you control.

During local development, that domain is usually a tunnel pointing at localhost. Tunnels change the rules in ways most guides never mention. This article covers how iOS Universal Links and Android App Links verify a domain, why a tunnel complicates that, and how to build a test setup that survives restarts. Details were checked against Apple, Android, ngrok and Cloudflare documentation as of November 26, 2026.

Why a Deep Link Opens the Browser Instead of Your App

A custom URL scheme such as myapp:// is only a registration. Any app can claim it, and the OS has no way to confirm the app actually owns it.

Universal Links (iOS) and App Links (Android) work differently. They use normal https:// URLs, and the OS hands them to your app only if your website proves it approves that app. If the proof fails, nothing errors out visibly. The link opens in the browser (or, on Android, in a chooser), and you get the symptom in this article’s title.

So the debugging question is never “is my navigation code wrong?” It is “did the OS verify my domain?” On both platforms, verification depends on a JSON file served from a /.well-known/ path, plus a matching declaration inside the app.

How iOS Verifies Universal Links

The apple-app-site-association file

Apple’s documentation describes a file named apple-app-site-association (no extension) hosted at https://<fully qualified domain>/.well-known/apple-app-site-association. You must host it over https:// with a valid certificate and with no redirects. Serving it as valid JSON with Content-Type: application/json is the safe choice.

A minimal file in the current recommended format looks like this:

{
  "applinks": {
    "details": [
      {
        "appIDs": ["ABCDE12345.com.example.app"],
        "components": [
          { "/": "/buy/*" },
          { "/": "/help/website/*", "exclude": true }
        ]
      }
    ]
  }
}

The app ID is your Application Identifier Prefix (Team ID) plus your bundle identifier. Apple’s debugging technote (TN3155) also accepts a legacy format with appID (a string) and paths (an array), but it advises against mixing the two formats because that may cause unexpected behavior.

The entitlement

Your app needs the Associated Domains capability with an entry like applinks:links.example.com. If your site uses several subdomains, each one needs its own entitlement entry and must serve its own association file.

The technote adds a wildcard rule. A file hosted at the root domain (https://example.com/.well-known/...) covers applinks:example.com and the wildcard applinks:*.example.com, but not specific subdomains such as applinks:www.example.com. Those need their own file at their own host.

Domains in applinks cannot contain a port number. applinks:example.com:8080 will not open your app, which matters for any tunnel that exposes a non-standard port.

The part that surprises everyone: Apple’s CDN

Starting with iOS 14 and macOS 11, apps no longer request the association file directly from your server. They request it from an Apple-managed content delivery network built for associated domains. If the CDN has an old copy, or no copy, it connects to your web server to fetch the latest.

According to Apple, the CDN requests your file within 24 hours of the app being installed. Devices then check for updates roughly once a week. There is no direct CDN invalidation option; to pull a newer copy, reinstall the app.

Two consequences follow:

  1. Your server must be reachable from any IP address, must not redirect, and must not block the CDN. Apple’s technote says the server should also accept all user agents, and suggests testing with a made-up one: curl -A "MyAgent-Bot/*" https://example.com/.well-known/apple-app-site-association. A 403 or 404 usually means your site denied access.
  2. You can see what Apple’s CDN has cached by requesting https://app-site-association.cdn-apple.com/a/v1/<your-domain>. This URL is widely used for the check but is not described in Apple’s own documentation. If it shows stale or missing content, devices that rely on the CDN will see the same.

The Developer-Mode Shortcut: ?mode=developer

For development, Apple provides an alternate mode that bypasses the CDN. You append a query string to the entitlement value:

applinks:links.example.com?mode=developer

Apple’s entitlement documentation says developer mode limits access to devices that are in developer mode. In this mode you can use any valid SSL certificate on your web server, including one the system does not trust. Apple recommends it for servers unreachable from the public internet and for testing association-file changes faster than the CDN can pick them up. It also warns you not to expose users to security risks such as machine-in-the-middle attacks.

Several details trip people up:

  • Turn on the device switch. Enable Developer Mode on the device, then go to Settings > Developer, scroll to the Universal Links section, and turn on Associated Domains Development.
  • It is for development builds only. Apple states that only apps signed with a development profile can use developer mode, and users must opt in on each device. TestFlight and App Store builds are not development-signed, so remove ?mode=developer before you ship them.
  • It changes your tunnel needs. Because developer mode connects directly to your server and tolerates untrusted certificates, an iOS-only test can run against a private server on your network without a public tunnel. Android still needs a publicly reachable HTTPS host with a valid assetlinks.json, so a tunnel remains the practical option for cross-platform testing.

How Android Verifies App Links

Android’s flow is more direct. If at least one intent filter has android:autoVerify="true", installing the app on Android 6.0 (API level 23) or higher triggers automatic verification of the hosts in your intent filters. The system looks at filters that include the VIEW action, the BROWSABLE and DEFAULT categories, and an http or https scheme. For each unique hostname, Android requests https://<hostname>/.well-known/assetlinks.json.

A valid file looks like this:

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "com.example.app",
    "sha256_cert_fingerprints": ["14:6D:E9:...:E5"]
  }
}]

Google’s hosting requirements are strict:

  • Content type application/json.
  • HTTPS, regardless of whether your intent filters declare http or https.
  • No redirects (no 301 or 302).
  • A file on every host your app supports. If your links cover multiple hosts, publish assetlinks.json on each one.

The signing-certificate trap

The sha256_cert_fingerprints field accepts multiple fingerprints, which you can use to cover debug and production builds. If you use Play App Signing, the fingerprint produced by running keytool locally will usually not match the one on users’ devices. Google points you to the correct snippet in Play Console under Release > Setup > App signing. A debug build installed over USB is signed with your debug key, so that fingerprint needs to be listed too, or verification fails.

Android-specific behavior worth knowing

  • On Android 11 (API level 30) and lower, the system makes your app the default handler only if it finds a matching file for all hosts in the manifest. One broken host can sink the whole filter.
  • On Android 12 and higher, you can trigger verification manually.
  • Only one app at a time can be associated with a given domain on a device. If another app already holds it, the user must disassociate that app before yours can take over.
  • Android 15 (API 35) and higher periodically re-verify domains in the background. Edits to assetlinks.json can take up to seven days to reach all devices. On Android 14 and lower there is no periodic re-verification, and updates are typically picked up only when the app is installed or updated.
  • On Android 15 and higher with Google services, assetlinks.json can also carry “dynamic” path, query and fragment rules (dynamic_app_link_components). They are evaluated in order, and they can only narrow what your manifest’s intent filters already declare. Google recommends broad manifest filters (scheme and host) plus server-side rules for path-level routing.

Why Tunnels Make This Harder

A tunnel gives your laptop a public HTTPS address, which is exactly what both verifiers need. The trouble is how that address behaves over time.

The random-URL problem

Many tunnel tools give you a different hostname on each run. Cloudflare’s documentation says a quick tunnel (cloudflared tunnel --url http://localhost:8080) gets a random trycloudflare.com address. It exists only while cloudflared runs, and the next run mints a different one.

Now connect that to what you just learned. On iOS, the host is baked into the entitlement, which is part of the signed build. On Android, it lives in the manifest intent filter. A new hostname therefore means:

  1. Edit the entitlement and manifest.
  2. Rebuild and reinstall the app.
  3. Wait for verification (Android) or CDN pickup (iOS without developer mode).
  4. Repeat after every tunnel restart.

That loop turns a ten-second check into a ten-minute chore, and it hides real bugs behind setup noise.

The stable-hostname fix

The better approach is to register one host, once. The options as of this writing:

  • ngrok: Every account, including free ones, gets one assigned dev domain that stays the same across agent restarts. You cannot choose or rename it on the free plan. ngrok’s announcement uses ngrok-free.dev as the example base domain, while its current docs show ngrok-free.app, so check Gateway > Domains in your dashboard for yours. Picking a custom ngrok domain such as your-company.ngrok.app requires a paid plan (the Hobbyist plan, per ngrok), and bringing your own domain is also a paid feature. Free-plan limits include 20k HTTP requests per month, 1 GB of bandwidth per month, and 3 concurrent endpoints.
  • Cloudflare Tunnel: A named tunnel keeps its identity as a record in your Cloudflare account, so stopping cloudflared leaves it in place. It can serve a stable hostname on a zone you control, such as dev.example.com. It requires a Cloudflare account and a domain on Cloudflare. Quick tunnels, by contrast, are meant for testing and carry no uptime guarantee. They return a 429 when they hit their request limit, and they do not support Server-Sent Events.

With a stable hostname, the entitlement and manifest are written once. Restarting the tunnel changes nothing the OS cares about, and your association files keep resolving at the same address.

The ngrok interstitial

On the free tier, ngrok injects a warning page in front of HTML browser traffic. After a visitor clicks through, a cookie suppresses it for 7 days on that domain. ngrok says this does not affect API or programmatic access, and that a paid plan removes it. The documented client-side workaround is to send an ngrok-skip-browser-warning header, but you cannot control the headers that Apple’s CDN or Android’s verifier send.

So do not assume the interstitial stays out of the way. Request your files with curl and, for iOS, check the CDN URL. If either returns an HTML page instead of JSON, verification will fail.

A Practical Testing Workflow

Step 1: Serve both files through the tunnel

Make your local server return the correct content for both paths with no redirects. That includes redirects done by a proxy, such as http to https or apex to www. Both files should be valid JSON, and Android specifically requires application/json.

Check them from outside your network:

curl -i https://dev.example.com/.well-known/apple-app-site-association
curl -i https://dev.example.com/.well-known/assetlinks.json

You want 200, JSON bodies, and no 301 or 302.

Step 2: Use a build variant for the tunnel host

Do not hard-code the tunnel host in production configuration. Google specifically warns against publishing an app with test URLs in the manifest that may not be publicly accessible (for example, ones reachable only over a VPN). Its workaround is to configure build variants so dev builds generate a different manifest. In practice:

  • Android: use a manifest placeholder for the host in a debug variant.
  • iOS: use a separate debug entitlements file that includes applinks:dev.example.com?mode=developer.

Step 3: Test iOS correctly

Apple’s technote is clear about how not to test: typing the URL into a browser’s address bar never opens the app, because that is direct navigation within the browser. Instead:

  1. Paste the link into Notes and long-press it. If everything is configured correctly, you will see options to open in your app and in the browser. Your choice becomes the default for that domain, so repeat the steps to change it.
  2. Or turn on Developer Mode, then go to Settings > Developer > Associated Domains Development > Diagnostics, type the full URL, and read the result.
  3. Remember that a link whose domain matches the page you are already browsing stays in the browser. Apple’s workaround is to use a different subdomain for links that should launch the app.
  4. On a Mac, run sudo swcutil dl -d <domain> to confirm the file downloads. Run sudo swcutil verify -d <domain> -j <file.json> -u <url> to test your URL pattern against a local copy. Excluded paths report a “blocked match.”
  5. If it still fails, take a sysdiagnose and open swcutil_show.txt. Search for your App ID. A Site/Fmwk Approval value of approved means Apple’s CDN approved your domain. unspecified or denied points to access problems or a domain missing from your entitlement.

Also note that web browsers, and apps registered as browsers, are not allowed to register universal links through applinks.

Step 4: Test Android correctly

  1. Validate the file with the Digital Asset Links API: https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://dev.example.com&relation=delegate_permission/common.handle_all_urls. Google’s Statement List Generator and Tester is another option.
  2. Install the app and wait at least 20 seconds for the asynchronous verification to finish.
  3. Check the state:
adb shell pm get-app-links com.example.app

A host showing verified passed. none means nothing is recorded yet, so the verifier may not be finished. legacy_failure or an error code of 1024 or higher means verification failed. Other states (approved, denied, migrated, restored, system_configured) mean the result was forced, migrated or set by the device.

  1. To rerun verification on Android 12 or later (apps targeting an older SDK first need adb shell am compat enable 175408749 com.example.app):
adb shell pm set-app-links --package com.example.app 0 all
adb shell pm verify-app-links --re-verify com.example.app

Wait a few minutes before reviewing the results.

  1. Test an actual tap:
adb shell am start -a android.intent.action.VIEW \
  -c android.intent.category.BROWSABLE \
  -d "https://dev.example.com/product/42"
  1. Starting in Android 17, adb shell am start --debug-link -a android.intent.action.VIEW -d "<url>" prints an “App Link Resolution Debug” report. It lists every candidate app that matched, which manifest attributes matched, the verification state, and any Dynamic App Links rules that were evaluated. That makes ambiguous chooser dialogs much easier to diagnose.

Keep in mind that user preferences take precedence over verification. A link that “works” on your test phone might only mean you once enabled the app to open supported links manually. adb shell pm get-app-links --user cur com.example.app shows the per-user selection state.

Troubleshooting Checklist

Symptom Likely cause
iOS opens Safari every time File not cached by the CDN, a redirect or 403/404 on the file, wrong Team ID or bundle ID in appIDs, or an applinks domain that doesn’t match the file’s host
Works in developer mode, fails on TestFlight Production builds use the CDN and can’t use ?mode=developer; the file must be public, unredirected and cached
Link from a page on the same domain stays in the browser Browsers treat same-domain navigation as in-browser; link from a different subdomain
iOS never picks up a new file CDN cache plus roughly weekly refresh; reinstall the app, or use developer mode while iterating
Android shows a chooser dialog Verification failed, wrong fingerprint, or another app already holds the domain
Works for example.com but not www.example.com Each host needs its own entitlement or intent filter and its own file
Link fails after the tunnel restarts Random hostname; move to a static or named tunnel
iOS applinks:www.example.com fails with the file only at the root A root-domain file covers the root and *.example.com, not specific subdomains
HTML or a warning page where JSON should be Tunnel interstitial or proxy rewriting the response; check with curl

Key Takeaways

  • A link opening in the browser almost always means domain verification failed, not that your routing code is broken.
  • iOS gets the association file from Apple’s CDN, not from your server. ?mode=developer on the entitlement bypasses the CDN for devices in developer mode, but it only works in development-signed builds and must not ship.
  • Android verifies assetlinks.json directly, requires correct signing fingerprints, and gives you adb commands to retrigger and inspect verification.
  • Random tunnel URLs force an entitlement change, a manifest change and a rebuild after every restart. A stable hostname is registered once.
  • Test with Notes, the Diagnostics screen, swcutil and adb, not by typing URLs into a browser.

FAQ

Why does my Universal Link open Safari instead of my app?

Most often the association file is unreachable, redirected, blocked, or not yet cached by Apple’s CDN, or the app’s entitlement does not match the domain serving the file. Testing by typing the URL into Safari also never opens the app.

Do I need to change the entitlement every time my tunnel URL changes?

Yes, if the tunnel hostname changes, because the host is part of the entitlement (iOS) and the manifest (Android). Use a stable hostname to avoid this.

What does ?mode=developer do?

It makes a device in developer mode fetch the association file directly from your server instead of Apple’s CDN, and it accepts any valid SSL certificate, even one the system doesn’t trust.

Can I use ?mode=developer in production?

No. Apple says only apps signed with a development profile can use it, so remove it for TestFlight and App Store builds.

How long does Android App Links verification take?

Wait at least 20 seconds after install for the asynchronous check, then query with adb shell pm get-app-links. File changes can take up to seven days to propagate on Android 15 and higher.

Can I include a port number in applinks?

No. Apple’s technote states that domains in applinks cannot contain a port, so a tunnel must expose the standard HTTPS port.

Sources

Originally published at https://instatunnel.my/blog/your-deep-link-opens-safari-not-your-app-testing-universal-links-and-android-app-links-through-a-tunnel

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.