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
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.Have the same problems. These are my steps to ‘fix’ this:
Configure Bundler
with your Mac’s IPI spent hours trying all possible fixes…
Another hints:
For me it was the XCode build which was targeted for
Release
, notDebug
.Simply navigate
Product > Scheme > Edit Scheme
and change theBuild Configuration
toDebug
.Turn off/on wi-fi on device / on mac, rebuild app
For me it was enough to remove node_modules folder
Then I have run
And reinstalled pods
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 ametro.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
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
What worked for me after trying everything I could, was creating a file
main.jsbundle
inside theios
folder, adding to the XCode project and target the file with the application using theTarget Membership
section (in XCode)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: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.
Window -> Devices and Simulators -> click on your iPhone-> make sure
Connect via network
checkbox is checked.Configure bundle
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.Make sure the Local Network permission is enabled for the app; otherwise iOS won’t be able to access your Mac and the jsbundle
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.