206

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 13

394

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.

Sign up to request clarification or add additional context in comments.

14 Comments

If you're seeing something like 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).
For me just react-native run-ios --device worked and the above command did not
If you get an error after running npm install -g ios-deploy, try running sudo npm install -g ios-deploy --unsafe-perm=true --allow-root
Note that you can run the mobile application in relase configuration on an iOS device with the device's UDID (you may get an error with --device option for device names having non-English characters: react-native run-ios --udid XXXX --configuration Release
getting ** 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 result
|
87

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

7 Comments

how do you get the device ID?
ios-deploy -c # when your device is plugged in
for me sudo npm install -g ios-deploy --unsafe-perm=true worked.
input device to usb-> Xcode->Window->Devices and Simulators->Identifier this is uuid(udid)
@jasonleonhard How does 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 either
|
84

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

3 Comments

using UDID method, I get the error : "error The device and udid options are mutually exclusive"
Please use xctrace list devices instead of xcrun instruments -s devices in xcode 13 and above.
Actually, it's now xcrun xctrace list devices
17

Actually, For the first build, please do it with Xcode and then do the following way:

  1. brew install ios-deploy
  2. npx react-native run-ios --device

The second command will run the app on the first connected device.

1 Comment

@famfamfam, The second command will start metro bundler and give you a terminal, you can see logs there.
11

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

Of course it had to be a different apostrophe...
10

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

I got a similar problem because the apostrophe was actually an unicode right single quotation mark. After copy-pasting the device name from the device list it worked.
i had the same problem, i had white space and brackets in my iphone's name. Thanks :)
9

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:

  1. sudo npm uninstall -g ios-deploy
  2. brew install ios-deploy

Comments

2

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

Now it's npx react-native run-ios --device=$( xcrun xctrace list devices | grep -v '(Simulator)' | tail -1 | sed 's/ (.*//')
2

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.

Comments

1

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)"

Comments

1

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

0

Given an iPhone named:

Ton’s iPhone

Just run:

xcrun xctrace list devices | grep -w "Ton" | awk -F "[()]" '{ print $1 }' | xargs -I iphone npx react-native run-ios --scheme Debug --device iphone

Comments

-1

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 [];
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.