Run react-native application on iOS device directly from command line?
IosReact NativeIos Problem Overview
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"
?
Ios Solutions
Solution 1 - Ios
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.
Solution 2 - Ios
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
Solution 3 - Ios
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 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 ;)
Solution 4 - Ios
Actually, For the first build, please do it with Xcode and then do the following way:
brew install ios-deploy
npx react-native run-ios --device
The second command will run the app on the first connected device.
Solution 5 - Ios
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
Solution 6 - Ios
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
Solution 7 - Ios
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 ’
Solution 8 - Ios
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'
Solution 9 - Ios
For you to run on specific ios device run
yarn ios --simulator "iPhone 8" if you are using yarn or
npx react-native run-ios --simulator="iPhone SE (1st generation)"
Solution 10 - Ios
I had same issue. Command npx run-ios
then select Physical Device
worked after renaming device name in Settings->General->About->Name. I used name with only letters without spaces and special symbols.