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"?
13 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:
npx 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.
EDIT: 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.
14 Comments
ios deploy does not support the following options: id, perhaps like me your iPhone is running iOS beta version and you'll have to use a beta version of Xcode. Try sudo xcode-select -s /Applications/Xcode-beta.app (assuming you have the correct Xcode beta app installed).react-native run-ios --device worked and the above command did notnpm install -g ios-deploy, try running sudo npm install -g ios-deploy --unsafe-perm=true --allow-rootreact-native run-ios --udid XXXX --configuration Release** INSTALLATION SUCCEEDED ** but nothing happens on the device... its 100% connected properly and recognized by Xcode. Tried both main answer and comments: react-native run-ios --device with same resultFirst 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
7 Comments
sudo npm install -g ios-deploy --unsafe-perm=true worked.ios-deploy -c work, it's not a command line tool? is it supposed to be yarn/npm ios-deploy -c or something, cause that didn't work eitherRun 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 xctrace list devices
OR
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 --udid 0412e2c2******51699
wait and watch to run your app in specific devices - K00L ;)
3 Comments
device and udid options are mutually exclusive"xctrace list devices instead of xcrun instruments -s devices in xcode 13 and above.xcrun xctrace list devicesActually, For the first build, please do it with Xcode and then do the following way:
brew install ios-deploynpx react-native run-ios --device
The second command will run the app on the first connected device.
1 Comment
Got mine working with
react-native run-ios --device="My’s iPhone"
And notice that your iphone name, the apostrophe s ' might be different. Mine is using this ’
1 Comment
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
2 Comments
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-deploybrew install ios-deploy
Comments
To automate this for any physical device, you could try using:
npx react-native run-ios --device=$(xcrun instruments -s devices | grep -v '(Simulator)' | tail -1 | sed 's/ (.*//')
Note: This uses the last listed device from xcrun that is not listed as a simulator. The device name is parsed from the xcrun instruments string pulling all characters that appear before the first (.
This works fine if you only have one apple device plugged in and its name does not include ( in it.
Otherwise, you may just want to run:
xcrun instruments -s devices
Pick your device (up to the version is the device name you should use).
Then run:
npx react-native run-ios --device='yourDeviceName'
1 Comment
The problem with me the device was recognized in Xcode 13 but couldn't find it in the devices list when run command
xcrun xctrace list devices
But After upgrade to Xcode 13.4.1 I could see the device in the devices list
Then I followed what's mentioned in previous posts first install ios-deploy package
yarn global add ios-deploy
Get your device id
xcrun xctrace list devices
Then
react-native run-ios --udid "your device id"
Comments
The --device argument only works if you have a simulator installed. I've also opened a PR to react-native-community/cli, it's a bug in there.
So if xcrun xctrace list devices returns all the correct devices and it still doesn't work, try installing a dummy simulator.
// @react-native-community/cli - parseXctraceIOSDevicesList
function parseIOSDevicesList(text: string): Array<Device> {
const devices: Array<Device> = [];
let isSimulator = false;
// Thats the problem causing the empty device list
if (text.indexOf('== Simulators ==') === -1) {
return [];
}