Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

282
Vistas
axios get data react native expo IOS

I'm building a mobile app,for android and IOS platform and i try to connect the back with the front, but i face a timeout error for the request on IOS, when it's work for android.

here my code:

const Login = ({ navigation }) => {
  const [openToggle, setOpenToggle] = useState(false);
  const [user, setUser] = useState([]);

  let baseURL = null;

  Platform.OS === "android"
    ? (baseURL = "http://10.0.2.2:8000")
    : (baseURL = "http://10.0.2.2:8000");

  useEffect(() => {
    const getAllUser = async () => {
      try {
        const users = await axios.get(`${baseURL}/api/user`);
        console.log("test");
        console.log(users.data);
        setUser(users.data);
      } catch (error) {
        console.log("erreur", error);
      }
    };
    getAllUser();
  }, []);

I'm on a simulator for android and on real Iphone for IOS.

erreur [Error: timeout exceeded]

I'm on the same wifi network for the simulator and the iphone.

Any advice?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

On android emulator 10.0.2.2 corresponds to the local machine. More Information Here That is why it works on android.

On iOS, iOS simulator is sharing local machine internet so localhost or 127.0.0.1 will point to your local machine.

So you have to use localhost or 127.0.0.1 on iOS.

If you are running your app on your iPhone/Android device you have to connect your phone with the same wifi network and use your machine ipaddress

Check this https://reactnative.dev/docs/running-on-device

Or you can get the machine ip from where the packager is loading from following code

import { NativeModules } from 'react-native';

const { scriptURL } = NativeModules.SourceCode;
const scriptHostname = scriptURL.split('://')[1].split(':')[0];
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda