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

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

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

  • 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.
  • Or turn on Developer Mode, then go to Settings > Developer > Associated Domains Development > Diagnostics, type the full URL, and read the result.

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.

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.ā€

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 br

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.