skip to Main Content

My Simulator works fine it connects to the development server first try. But on my real device I have to delete node modules, reinstall Podfiles, clean building folder and delete Derived Data then it loads a bunch of time in Xcode and finally connects to dev server. But after I stop it and I want to run it again it wont connect. I used to able to just run npm start and launch my app on my phone and it connected automatically, and I could make changes, it refreshed and everything, but now even with Xcode running it doesn’t work 10/9 times.

And yes I’m on the same network with my phone as the computer. I tried to set my mac’s IP on Bundle Settings on the phone, no success.

Anyone got any idea?

12

Answers


  1. As a rule of thumb whenever running an app on iOS device, or even a simulator I’ve used before I uninstall the app before running again.

    Unsure if you had a previous version in this instance but worth a shot in the dark.

    I find running via Xcode rather than react-native run-ios is more consistent also.

    Login or Signup to reply.
  2. Have the same problems. These are my steps to ‘fix’ this:

    • Ensure that you don’t have ethernet internet cable plugged in. Only wifi network (iPhone and Mac has to be on the same wifi network)! I think that this was the main problem in my situation.
    • Turn off the metro, the app usually starts (because the native app build contains also js build).
    • Then run the metro again.
    • Shake your device and Configure Bundler with your Mac’s IP
    • it seams that only resave of this screen helps – so you don’t have to spend time with finding and entering the IP
    • Then it should connect to your metro

    I spent hours trying all possible fixes…

    Another hints:

    Login or Signup to reply.
  3. For me it was the XCode build which was targeted for Release, not Debug.

    Simply navigate Product > Scheme > Edit Scheme and change the Build Configuration to Debug.

    Login or Signup to reply.
  4. Turn off/on wi-fi on device / on mac, rebuild app

    Login or Signup to reply.
  5. For me it was enough to remove node_modules folder

    rm -rf node_modules
    

    Then I have run

    npm install; 
    npm start -- --reset-cache;
    

    And reinstalled pods

    cd ios; rm -rf Podfile.lock Pods; pod --repo-update install; cd ..;
    
    Login or Signup to reply.
  6. Once the app is launched shake the device to enter the dev menu, click configure bundler and put the IP address of the machine running metro. Mine was set to default localhost. There is also a metro.config.js that I think you can set this up to use a spec.

    If you’re on a mac the local IP address can be found in system pref -> network -> WIFI

    Login or Signup to reply.
  7. The only thing the predictably works for me is connecting with the mac to the iphone’s hotspot.

    Not ideal, but nothing else worked for me 🤷‍♀️

    I’m on m1 in case it matters

    Login or Signup to reply.
  8. What worked for me after trying everything I could, was creating a file main.jsbundle inside the ios folder, adding to the XCode project and target the file with the application using the Target Membership section (in XCode)

    Login or Signup to reply.
  9. On iOS 16 the real device can’t connect on metro bundler. To verify this, open safari and enter your mac’s IP, eg. 192.168.1.10:8081 (8081 is the bundler port), if the page won’t load then there’s a network issue.

    Solution:
    Untick the Disable unless needed checkbox under Mac network settings:
    enter image description here

    This will put the iOS device in hotspot mode but the mac will continue using the WiFi connection for internet browsing. Don’t know what kind of sorcery this is but it works.

    Login or Signup to reply.
    • Make sure your Mac and iPhone are connected to the same wifi.
    • In your xcode go to:
      Window -> Devices and Simulators -> click on your iPhone-> make sure Connect via network checkbox is checked.
    • Shake your iPhone -> in the poped up modal select Configure bundle
    • Press and hold Option key and click on your wi-fi icon in the menu bar. Under your wifi network there will be your IP address. Paste it to the modal from previous step. No need to specify port and file name.
    Login or Signup to reply.
  10. Make sure the Local Network permission is enabled for the app; otherwise iOS won’t be able to access your Mac and the jsbundle

    Login or Signup to reply.
  11. If you’re on:

    IOS: 16.0 >

    XCode: 14.0 >

    Make sure your iPhone and Mac are on the same wi-fi.
    Go into XCode > Click your project > Build Phases > Bundle React Native Code and Images > tick the box for ‘For Install Builds Only’.

    If it’s already ticked, untick the box then build. Then re-tick the box then build again.

    Your app should request local network access this is the key fact with this issue. You can check in the settings of your app on the iPhone.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search