The phone can’t reach localhost, and it blocks plain HTTP
Two things usually cause it. On a real phone, localhost means the phone itself, not your computer. And release builds on iOS and Android refuse plain http:// by default. The simulator hides both problems. The fix that lasts is to deploy the API to a host with an HTTPS address and point the app at that URL.
What each device means by localhost
| Running on | localhost reaches | To reach your computer |
|---|---|---|
| iOS Simulator | Your Mac | localhost works |
| Android Emulator | The emulator | 10.0.2.2 |
| Physical phone on Wi-Fi | The phone | Your computer’s LAN IP, while on the same network |
| Physical phone on mobile data | The phone | Not reachable. Deploy the API |
Why plain HTTP fails
iOS App Transport Security blocks non-HTTPS connections unless the app declares an exception. Android blocks cleartext traffic by default for apps targeting Android 9 (API 28) or later. Development builds sometimes allow it, so the bug can appear only in a release build or TestFlight. You can add exceptions, but stores review them and they leave users’ traffic unencrypted. Use HTTPS instead.
Give the API a real HTTPS address
Deploy the API to Bothosting as an HTTP app, bound to 0.0.0.0 on SERVER_PORT. Copy its HTTPS address and request a known route from your phone’s browser first. If the browser gets the JSON, the app will too once its base URL points there.
// config.ts
export const API_URL = __DEV__
? 'http://10.0.2.2:3000' // Android emulator only
: 'https://api.example.com';If the browser also fails, the server isn’t listening where the platform expects. See an API that is listening but unreachable and hosting a mobile app’s backend.