Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

287
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!