4

I have been reading React Native's documentation as well as forums, and answers to similar questions but cannot figure out how to run my application on my device.

I have tried what was mentioned in this question "Run react-native application on iOS device directly from command line?", as well as deleting the build folder from the ios directory and rerunning the script. I will run this command npm run ios --device "Anthony’s iPhone", but it results in this Launching iPhone 6 (iOS 11.3)... I have also tried running npm run ios --simulator "iPhone 5s" but again I get Launching iPhone 6 (iOS 11.3).... I am not sure where to go from here, more information can be seen below. Of course, the simulator is always launched and functions properly but I would like to control whether it runs on a device or in which simulator.

Anthonys-MacBook-Pro:fitness-app anthonysette$ npm run ios --device "Anthony’s iPhone"

> FitnessApp@0.1.0 ios /Users/anthonysette/Documents/fitness-app
> react-native run-ios "Anthony’s iPhone"

Scanning folders for symlinks in /Users/anthonysette/Documents/fitness-app/node_modules (15ms)
Found Xcode workspace FitnessApp.xcworkspace
Launching iPhone 6 (iOS 11.3)...
Building using "xcodebuild -workspace FitnessApp.xcworkspace -configuration Debug -scheme FitnessApp -destination id=28DE4434-4D1A-4B5E-8C16-0AC2C101F8E0 -derivedDataPath build"
User defaults from command line:

Edit: Added info from package.json

My package.json has a portion called scripts which contains the following

  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "rename": "node ./bin/rename.js",
    "start": "react-native start",
    "test": "jest"
  },
Anthony Sette
  • 777
  • 1
  • 10
  • 26
  • Can you also try this `react-native run-ios --device`? – Pritish Vaidya Aug 10 '18 at 16:56
  • @PritishVaidya Just tried that, but for me `npm run ios` runs `react-native run-ios`. The results of that command was `Anthonys-MacBook-Pro:fitness-app anthonysette$ react-native run-ios --device bash: react-native: command not found` – Anthony Sette Aug 10 '18 at 16:58
  • Check my edit, added some info on the package.json file in my project. – Anthony Sette Aug 10 '18 at 17:00
  • 1
    You can either install `react-native cli` globally or add a script to your package.json as `"ios-device": "react-native run-ios --device"` and run `npm run ios-device` – Pritish Vaidya Aug 10 '18 at 17:01
  • @PritishVaidya That worked!!! I now get this `Could not find device with the name: "true". Choose one of the following: Anthony’s iPhone Udid: __UID__ Anthony’s MacBook Pro Udid: __UID__ Anthonys-MacBook-Pro:fitness-app anthonysette$`, how do I choose? Also if you would like to submit that as an answer I would be happy to mark it as answered for other people to see! – Anthony Sette Aug 10 '18 at 17:03
  • I think this is working `npm run ios-device "Anthony’s iPhone"` – Anthony Sette Aug 10 '18 at 17:07

2 Answers2

3

The npm run ios as defined your script will run react-native run-ios. Therefore you can either install react-native cli globally and use

react-native run-ios --device "Anthony’s iPhone"

or add a new script to your package.json as

"ios-device": "react-native run-ios --device"

and run npm run ios-device "Anthony’s iPhone"

Pritish Vaidya
  • 21,561
  • 3
  • 58
  • 76
-1

I would suggest you to install "create-react-native-app" to create react native app. You can run your app in your device through "expo". Run your app with "npm start" command. Download and install expo in your phone and scan the generated QR code. It also supports hot reload.

Note - Make sure your computer and phone are on same network.

  • I had previously done this and in most cases, it would work but after ejecting, or starting with the starter kit from `react-native-firebase` (already ejected) you cannot run the application through expo. (As far as I am aware, I could be wrong) – Anthony Sette Aug 10 '18 at 17:14