A captive portal is the page a guest Wi-Fi network shows before it lets a device reach the internet: the hotel room-number form, the airport "accept terms" button, the train voucher page. If you build anything that touches the network on a phone (a sync engine, a chat client, a VPN, an offline-first app), captive portals are one of the most common reasons your "online" state is wrong.

This post explains how iOS and Android detect a captive portal, what your app sees while one is in the way, and a few rules that keep apps from breaking on hotel Wi-Fi.

What does the network actually do?

A captive portal network lets the device join the Wi-Fi and get a local address, then holds its traffic at the gateway. Any plain HTTP request is answered with the portal page instead of the page asked for. Once the user finishes the page, the gateway marks the device (usually by its hardware address) as approved for a set time, often a day.

HTTPS requests cannot be answered that way without breaking the certificate check, so they simply fail or time out. That is the first thing to remember: while a portal is in the way, your HTTPS calls fail, but the device reports Wi-Fi as connected.

How does a phone know there is a portal?

Each OS requests a known test URL over plain HTTP every time it joins a network, and compares the answer with what it expects.

  • iOS / macOS request a page under captive.apple.com and expect a tiny HTML page that says Success.
  • Android requests connectivitycheck.gstatic.com/generate_204 and expects an empty HTTP 204 response.

If the expected answer comes back, the network is treated as online. If anything else comes back (a redirect, a 200 with a login form), the OS decides a portal is present and opens it in a small sign-in window. There is also a standard way for networks to announce the portal directly: RFC 8910 (portal URL in DHCP / Router Advertisements) and RFC 8908 (the Captive Portal API), which newer OS versions use when the network supports them.

What does your app see?

On both platforms the system exposes the result:

  • On Android, NetworkCapabilities has NET_CAPABILITY_CAPTIVE_PORTAL while the portal is unresolved and only gains NET_CAPABILITY_VALIDATED after the check passes.
  • On iOS, NWPathMonitor can report the Wi-Fi path as satisfied while your requests still fail; there is no public "captive" flag, so the honest signal is a failed request, not the path status.

The trap is treating "has Wi-Fi" as "is online". A queue that retries five times in ten seconds will burn through its retries before the user has even seen the room-number form.

Rules that keep apps from breaking on hotel Wi-Fi

  1. Wait for validation, not for a link. On Android, gate sync on NET_CAPABILITY_VALIDATED. On iOS, treat the first failed request after joining Wi-Fi as "maybe a portal" and back off instead of erroring out.
  2. Never try to load the portal yourself over HTTPS. It will look like a certificate error. Let the OS sign-in window do it, or send the user to a plain-HTTP address.
  3. Say what is happening. "This Wi-Fi needs you to sign in first" is a better message than "Network error", and it tells the user what to do.
  4. Re-check after approval. Most portals approve a device for a limited time. When it expires, the portal comes back mid-session; the same detection should run again instead of assuming the network stayed good.
  5. If you run a tunnel, start it after the portal is done. A VPN or any always-on tunnel that starts before approval cannot reach its server, and some will report "connected" with nothing flowing. The usual order is: join, finish the portal, then bring the tunnel up, and re-check after it reconnects.

A quick way to test

You do not need a hotel. A spare router with a guest-portal feature, or a small local gateway that answers every HTTP request with a redirect, reproduces the behaviour. Join it with a phone, watch the system sign-in window appear, and check what your app does in the minute before the user finishes the form.

Disclosure: written by an AI agent for the team behind a VPN app, which is how we ran into most of these cases. Corrections are welcome in the comments.