React-Native IOS real device does not connect to Metro server - xcode

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?

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:
https://github.com/facebook/react-native/issues/29587
https://github.com/facebook/react-native/issues/29396
delete pods file
update ios pod
cleanup DerivedData
update react-native (I don't have problem with clean RN app)
update xCode, iPhone, Mac
try different iPhone device

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.

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

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

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 ..;

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.

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.

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.

Turn off/on wi-fi on device / on mac, rebuild app

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)

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.

Related

Xcode 12.3 keeps freezing

I updated to the latest AppStore release of Xcode (12.3, 12C33).
It worked fine for an hour or two. After that it started to constantly freeze after being open for a few seconds to minutes.
I've tried the following, all without success so far:
restart macOS
clear derived data
tried with different projects
updating to latest macOS 11
Any other ideas or suggestions how to fix this?
Update
I can confirm that this is fixed in Xcode 12.5
I found an answer by Darr on the question "Xcode freezes after upgrade to 12.3" on Apple's developer forums that worked for me:
Unpairing my device connected via network and using only lightning cable seems to have resolved the issue for me.
Xcode > Window > Devices and Simulators > device > Connect via network
After going mad, I fixed this by removing all devices from Devices and Simulators (I had connect via network activated).
For now, it's working fine.
Power off your Apple Watch
Xcode may hang if the host Mac is connected to an iOS device which has one or more companion watches. The hangs occur when the watches aren't fully prepared for development, or if they are experiencing poor wireless connectivity. (72490921) (FB8945320)
Workaround: Power off the watches, or unpair them from the iPhone.
Xcode 12.4 Release Notes
You can force Xcode to freshly prepare a watch for development using these steps:
Force-quit Xcode.
Power-off and disconnect all iOS device from the Mac.
Reboot the Mac.
Launch Xcode, close all projects, and open the Devices and Simulators window.
Power-on and unlock an iOS device and its companion watchOS devices by entering the passcode as required.
Plug the iOS device into the Mac using USB cable.
Check each iOS device and each watch for any pairing request and approve the requests.
Monitor the status of device preparation in the Devices and Simulators window. If Xcode presents device-preparation errors, follow the guidance in the error message to resolve the error.
Once Xcode finishes preparing the iOS device and its companion watches for development, repeat steps 5 through 8 for each remaining iOS device and its companion watches until you verify that Xcode has prepared all devices for development. You may now open your Xcode projects and resume development.
I've been having the same problem. I had an iOS device connected via USB, unplugged it and it un-froze. Then I continued to have issue requiring force close each time.
I then clear derived data and things have been fine. I opened a StickerPack project and also had the same issue. Clearing DerivedData also fixed it.
Clear Derived Data:
Xcode pulldown menu > Preferences > Locations tab
Click the little arrow next to the path under Derived Data.
Delete the entire folder for you project. It will look like "MyAppName-bwonddotztrgkkfexrjxoncvmjit"
See this explanation about whether it's safe to delete DerivedData for your project.
I had the same problem with appstore version and someone advised to install from site, now it works fine. https://developer.apple.com/download/more/
Disable WLAN on my iMac fixes the problem currently.
Hope they will releast a fix very soon.
Xcode 12.3 is unstable and many times it crashes.
I reverted back to Xcode 12 and copied disk image of 14.3 in Device Support folder of Xcode (Contents > Developer > Platforms > iPhoneOS.platforms-DeviceSupport).
This I needed to debug on iPhone device having version iOS 14.3
https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/releases
I recently had similar situation. My Xcode 12.3 project could not be opened. I tried to open directly from popup that appears on start of the Xcode.
What worked for my was to downgrade Xcode to 12.2 and launch Xcode on new project. And then click my old one.
Maybe it would work without downgrading but I didn't check.
I had this problem too. I fixed it by going Devices and Simulators in the Windows file and disconnecting the iPhone reference I had for my phone when testing and app. Since the phone was no longer connected, its presence seemed to create a freeze.
In my case XCode 12.5 hangs/freezes on startup more or less instantly, right after it opens kind of an empty workspace.
I removed everything that I could imagine that deals with XCode on my machine, but it didn't help.
At the end I just used the hotkey for "Close Workspace" - Ctrl+Alt+Cmd+W
I hit this combo very often, very fast right after opening XCode and it worked!
The strange empty workspace showed up and closed instantly - now I could select other projects and everything works again.
There could be the multiple reasons and in my case reason was source control
preferences > Source Control > uncheck Enable source control
I have these performance problems with the newly updated Xcode from the AppStore to 12C33 (Xcode frozen for many seconds, instability of interface builder, etc.) only with apps which have frameworks added with cocoa pods and when working in the xcworkspace-file. (Integration of frameworks with Catharge even fail with error message 65). I'm running Xcode under macOS Catalina. Don't know what the technical reason could be, hence would appreciate if someone has an idea on this how to fix it.
Update: In the meantime I could fix it:
I eliminated my own devices from the device list and did then a deintegration and a new install of the cocoa pods for the projects. Afterwards I setup my devices again in the device list and all worked well again. Only eliminating and reintegration of my devices as described above didn't work in my case.

Not being able to install on device After updating to iOs 12 (NativeScript Vanilla)

The app gets built and it even seems to get installed, but no icon shows up on home screen.
Any thoughts?
Give this a try:
Make sure you run current iOS and Xcode versions
Open iTunes and connect your device. Make sure you get to the usual device view that let's you sync etc.
Open Xcode and connect your device. Wait for it to finish processing symbol files etc. (Of course make sure, command line tools are installed...)
If you're being asked to trust the counterpart device do so.
Run tns platform clean ios
Try building and running your app

App suddenly will not run on device

I have been running an app on my ipod that I've been developing for a while now and all of a sudden it won't run. I haven't changed xcode or macos; I've deleted the derived data folder; I've restarted the device, computer and xcode and cleaned.
The error I'm getting is: "could not start debugserver on MyDevice when trying to launch My.app"
My provisioning profile and device are green. I can't understand what I could possibly have changed.
Any ideas?
Thanks.
Restart Xcode and the device and you should be fine.
just CMD+shift+K, clean you project. when it's done, it should be work. at least for me.
Try deleting the installed application from your phone. That worked for me as none of the above methods did.
I had this issue while I was testing iOS beta. I updated iOS version on device and I had to restart xcode and then reconnect to
Restart xcode.
Unplug iPhone/iPad from usb cable (If connected with usb cable).
Turn off wifi and connect again (If you are using wifi debug).
Clean project.
Run your app again.

Xcode Doesn't Recognize My Device After OS Upgrade

This has to be a simple configuration issue, but I don't know my way around the build settings very well.
I upgraded my iPad from 4.3 to 5.0. I am using Xcode 4.2. When I plug my device in, it is not showing up on run button, and I have a message that it can't run using the selected device.
What do I have to do?
Open Xcode, go to Window -> Organizer and find your device. Click the "Use for Development" button to get Xcode to recognise it again.
go to your iphone device, settings->Reset->Reset All Settings. Close Xcode, restart XCode, device should be in the list now.
Restarting USB process worked for me.
Run sudo pkill usbmuxd on terminal
or
Open Activity Monitor and select Disk by tapping from segment control and search usbmuxd, select the same and force quite/quite.
Note: before doing above stuff, remove device and quite Xcode.

Sharing iPhone Apps for the Simulator

iPhone Apps built for the simulator are stored here:
/Users/<username>/Library/Application Support/iPhone Simulator/User/Applications
Is it possible to copy the <GUID>.sb and <GUID> directory and install them on a different computer (with Development tools installed)?
This would be very useful for testing/demoing with out having to buy iPhones for all the managers and external clients.
I found a way that requires just a little more setup, but is much easier for non-developers:
Instructions for your users/testers:
Install Xcode following Apple's instructions
Double-click the attached application - the iPhone simulator will launch, install the app and start it automatically.
How to set it up:
Download and unzip (to a folder on your desktop or wherever) 'Simulator Bundler' from: http://github.com/landonf/simlaunch/downloads
Set your XCode build target to the required Simulator configuration (iPad/iPhone/which iOS version)
Do a 'Build and archive'
Find it: select 'Archived applications' in the Organizer, right click the relevant build, select "Reveal archived application in Finder"
Drag the application (yourAppName, no extension) onto the Simulator Bundler app
Done. This will create a self-contained Mac OS X yourAppDisplayName.app file in the same folder (with your app's icon as the icon) that you can stick up on an FTP server or email to your users/testers.
--
I think it's much neater/slicker than having to explain where to copy files, how to launch the simulator and so on.. And if anything gets messed up they can just uninstall via the familiar tap-and-hold + (x) gesture in the simulator UI, then double-click the app you sent them again.
You can also produce several of these packages changing the bundle identifier between builds, allowing them to be installed side by side in your testers' simulators; say for getting some user feedback on different UI designs, or configure one for Production and one for Staging/QA servers, so your content editors can check their changes before they go live or whatever..
The ability to reinstall the app from a desktop icon is also very convenient for localisation testing: launch the simulator, uninstall the app if present, set the required region format and language, double click the icon on your desktop, test; repeat for each required locale. (guarantees a fresh install each time, I've found that switching language with the app installed can result in all sorts of strange behaviour)
Yes, if you send those files to another person, and they put them into that directory, they can test the applications in the iPhone Simulator as well :)

Resources