190

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

Idan
  • 5,405
  • 7
  • 35
  • 52
Aakash Sigdel
  • 9,060
  • 5
  • 33
  • 38

13 Answers13

370

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.

Charney Kaye
  • 3,667
  • 6
  • 41
  • 54
Kamil Sarna
  • 5,993
  • 1
  • 32
  • 22
  • 2
    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). – paulvs Oct 14 '17 at 03:25
  • 76
    For me just `react-native run-ios --device` worked and the above command did not – narek Dec 27 '17 at 16:30
  • 1
    When I did react-native run-ios --device "jose's iPhone" I got an error saying the name was incorrect. Then I just ran react-native run-ios --device and terminal said since no name was provided It will use first available device which was my iphone that was connected. – Jose Apr 19 '18 at 03:24
  • 18
    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` – Eric Wiener Apr 23 '18 at 15:39
  • 6
    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` – Gürol Canbek Sep 11 '18 at 23:21
  • 9
    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 – Blue Bot Sep 16 '18 at 11:14
  • @BlueBot: Have you check the Signing Identity are the same? I have two Identity, my own Identity and my company's Identity. But it is building using wrong Identity and can't install on device, even though build was successful – Nay Jan 26 '19 at 04:57
  • 1
    Also note that there are different versions of apostrophes, such as `’` vs. `'`. – Andrew Koster Feb 05 '19 at 19:58
  • @narek It worked for me `react-native run-ios --device` First I installed `npm install -g ios-deploy` then I run `react-native run-ios --device` – Raj Rj May 10 '19 at 09:50
  • 1
    Terminal show `info Installing and launching your app on xxxiPhone` but the app is not open on my device. I have to open manual. And, device can not wakup in during this. How to keep device awake while app is running ? Thanks ! – Shinichi Feb 16 '20 at 04:08
  • if you run `react-native run-ios --device` it will grab the first device available. `Using first available device named "iPhone van Dennis" due to lack of name supplied.` – 0x1ad2 May 07 '20 at 10:22
  • @BlueBot Were you able to find the solution? I'm suddenly facing the same issue as yours. I tried Nay's solution but it didn't work for me. I even tried reverting my commit but nothing changed. – Dangular Feb 02 '21 at 04:35
  • @Dangular no, after shedding a good amount of hours and tears, I just went building from within Xcode. Meaning I need to bundle my js code then build the project from Xcode and RN debug can't be used this way so Im debugging via xcode logs. Really ugly dev cycle but works – Blue Bot Feb 02 '21 at 09:04
  • One strange behavior I found is that `info Installing and launching your app on DEVICE_NAME` doesn't hang and jumps to `success Installed the app on the device.` **ONLY IF** your iPhone is locked, meaning the screen is off. I believe the `launching` part is causing the trouble. – Dangular Feb 03 '21 at 04:00
84

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
Kerem Baydoğan
  • 10,475
  • 1
  • 43
  • 50
jasonleonhard
  • 12,047
  • 89
  • 66
76

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

kuldip bhalodiya
  • 992
  • 7
  • 11
14

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.

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
  • @famfamfam, The second command will start metro bundler and give you a terminal, you can see logs there. – AmerllicA Sep 07 '22 at 08:13
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

Damitha Raveendra
  • 1,721
  • 17
  • 24
  • 2
    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. – Toma Mar 27 '20 at 15:01
  • 1
    i had the same problem, i had white space and brackets in my iphone's name. Thanks :) – Philip Frerk Feb 18 '23 at 18:20
9

If you get this error ios-deploy@x.x.x 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
Cedriga
  • 3,860
  • 2
  • 28
  • 21
7

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 ’

Js Yau
  • 135
  • 1
  • 9
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'
conmak
  • 1,200
  • 10
  • 13
  • Now it's npx react-native run-ios --device=$( xcrun xctrace list devices | grep -v '(Simulator)' | tail -1 | sed 's/ (.*//') – Oyeme Jun 21 '22 at 15:08
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.

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"

A.A.
  • 81
  • 2
0

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)"
Andrew Ananda
  • 90
  • 1
  • 3
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
-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 [];
  }
Simon
  • 1
  • 1
  • 5