The bug reports come from hotels, airports, trains and offices: "The app says there's no internet, but I'm on Wi-Fi." Or the opposite: the app spins forever, then fails with a certificate error or a JSON parsing error. On the developer's home network none of it happens.
The phone is connected to a network. That network just isn't giving it the internet, at least not yet. Here's what that looks like from the app's side and how to handle it.
Three kinds of "connected"
- A captive portal. Hotel, airport and café Wi-Fi often block traffic until the user accepts terms or logs in on a web page. Until then, the network intercepts requests: plain HTTP gets a redirect or an HTML page, HTTPS usually fails, and DNS may answer with the portal's address for every name.
- Wi-Fi with a dead uplink. The router is up and hands out addresses, but its connection to the internet is down. Connections time out instead of being refused.
- A network that blocks your hosts. Corporate, school or public networks that filter by domain or port. Some hosts work, yours doesn't.
In all three, the operating system reports an active Wi-Fi interface, and a naive "are we online?" check says yes.
What the app actually sees
- HTTPS through a captive portal typically fails during the TLS handshake. The portal can't present a valid certificate for your domain, so you see a certificate error (on iOS, codes like
-1202or-1200; on Android, anSSLHandshakeException) or a timeout. To the user it looks like your server is broken. - Plain HTTP through a captive portal can come back as
200 OKwith the portal's HTML, or as a302to the login page that the client follows. If the app decodes the body as JSON, the error is about an unexpected<, not about the network. - A dead uplink gives connection or DNS timeouts, which can take as long as your timeout settings allow. With default settings that can be a minute or more before the user sees anything.
What the OS knows (and what it doesn't)
Both platforms check connectivity themselves when a network is joined, and both expose some of that:
- Android:
NetworkCapabilitieshasNET_CAPABILITY_INTERNET(the network says it should provide internet) andNET_CAPABILITY_VALIDATED(the system actually reached its test server through it). A captive network may also carryNET_CAPABILITY_CAPTIVE_PORTAL.INTERNETalone doesn't mean it works;VALIDATEDis the closer signal. Register a callback withConnectivityManagerto hear when it changes, rather than checking once. - iOS:
NWPathMonitorreports a path as.satisfiedwhen there's a usable route, which doesn't guarantee your server is reachable. The system usually shows its own sign-in sheet when it detects a captive portal on joining Wi-Fi, but if the user dismisses it, the device can stay on that network with no real internet.
Apple's guidance has long been not to preflight a request with a reachability check: try the request, and handle the failure. A check can be wrong in both directions, and it adds a delay to every request.
Handling it in the app
- Classify the failure before you show it. A certificate error on a host that works for everyone else, or an HTML body where you expected JSON, points to the network, not your server. Show "This Wi-Fi network may need you to sign in, or try mobile data" instead of a generic error or "Our servers are down".
- Check the
Content-Typebefore decoding. If it'stext/htmlon a JSON endpoint, report that as a network problem with the status code and final URL. - Don't wait for the full timeout when you don't have to. On iOS,
waitsForConnectivityon the session configuration lets a request wait for a usable path instead of failing at once; pair it with a sensibletimeoutIntervalForResourceso it doesn't wait for the 7-day default. On Android, reacting to the network callback (for example retrying when a network becomesVALIDATED) avoids polling. - Retry when the network changes, not on a timer. When the user signs in to the portal or switches to mobile data, the OS reports a network change. That's the moment to retry, once.
- Low Data Mode and metered settings are a separate case. On iOS, if a request sets
allowsConstrainedNetworkAccess = falseand the user has Low Data Mode on, the request fails with a "not connected" error even though the network works. Check the error'snetworkUnavailableReasonbefore telling the user they're offline.
Testing it
- Fake a captive portal with a proxy or local server rule: answer every request to your API with
302to an HTML page, or200with an HTML body. Check that the app shows a network message, not a decoding crash. - Fake a dead uplink: a hotspot or travel router with its WAN cable unplugged, or a network conditioner profile with 100% packet loss. Measure how long the app takes to show an error and whether the UI stays usable.
- Test the transition: start on the "dead" network, then fix it (plug the cable back in, or switch to mobile data) and check that the app recovers without being restarted.
- Look at the real thing when you can. Connect a test phone to a public Wi-Fi network, don't accept the portal, open the app, and watch the requests it sends and the responses it gets.
This article was created with the help of AI.