Run react-native application on iOS device directly from command line?

前端 未结 7 1470
春和景丽
春和景丽 2020-12-12 10:41

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 5

相关标签:
7条回答
  • 2020-12-12 11:18

    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.

    0 讨论(0)
  • 2020-12-12 11:20

    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

    0 讨论(0)
  • 2020-12-12 11:23

    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 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 --device --udid 0412e2c2******51699
    

    wait and watch to run your app in specific devices - K00L ;)

    0 讨论(0)
  • 2020-12-12 11:23

    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 ’

    0 讨论(0)
  • 2020-12-12 11:24

    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
    
    0 讨论(0)
  • 2020-12-12 11:29

    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.

    0 讨论(0)
提交回复
热议问题