Is it possible to run react-native application on an iOS device directly from the command line like we do on simulator with react-native run ios --simulator "iPhone 5s"
?
8 Answers
The following worked for me (tested on react native 0.38
and 0.40
):
npm install -g ios-deploy
# Run on a connected device, e.g. Max's iPhone:
react-native run-ios --device "Max's iPhone"
If you try to run run-ios
, you will see that the script recommends to do npm install -g ios-deploy
when it reach install step after building.
While the documentation on the various commands that react-native offers is a little sketchy, it is worth going to react-native/local-cli. There, you can see all the commands available and the code that they run - you can thus work out what switches are available for undocumented commands.
First install the required library globally on your computer:
npm install -g ios-deploy
Go to your settings on your iPhone to find the name of the device.
Then provide that below like:
react-native run-ios --device "______\'s iPhone"
Sometimes this will fail and output a message like this:
Found Xcode project ________.xcodeproj
Could not find device with the name: "_______'s iPhone".
Choose one of the following:
______’s iPhone Udid: _________
That udid is used like this:
react-native run-ios --udid 0412e2c230a14e23451699
Optionally you may use:
react-native run-ios --udid 0412e2c230a14e23451699 -- configuration Release
Run this command in project root directory.
1>. List of iPhone devices for found the connected Real Devices and Simulator. same as like adb devices command for android.
xcrun instruments -s devices
2>. Select device using this command which you want to run your app
Using Device Name
react-native run-ios --device "Kool's iPhone"
Using UDID
react-native run-ios --device --udid 0412e2c2******51699
wait and watch to run your app in specific devices - K00L ;)
If you get this error [email protected] preinstall: ./src/scripts/check_reqs.js && xcodebuild ...
using npm install -g ios-deploy
Try this. It works for me:
sudo npm uninstall -g ios-deploy
brew install ios-deploy
Just wanted to add something to Kamil's answer
After following the steps, I still got an error,
error Could not find device with the name: "....'s Xr"
After removing special characters from the device name (Go to Settings -> General -> About -> Name)
Eg: '
It Worked !
Hope this will help someone who faced similar issue.
Tested with - react-native-cli: 2.0.1 | react-native: 0.59.8 | VSCode 1.32 | Xcode 10.2.1 | iOS 12.3