React Native Change Default iOS Simulator Device

前端 未结 13 1572
轮回少年
轮回少年 2020-12-12 09:56

When I run this command:

react-native run-ios

My app runs by default in the iPhone6 simulator device:

Found Xcode project R         


        
相关标签:
13条回答
  • 2020-12-12 10:05

    1) Rename your simulator, If simulator with same name but different iOS version

    Xcode -> Window -> Devices and Simulators -> Simulators.
    

    2) Open your react native project folder

    3) Edit package.json

    "scripts": {
        "start": "node node_modules/react-native/local-cli/cli.js start",
        "test": "jest",
        "flow": "node_modules/.bin/flow",
        "start-iphone6": "react-native run-ios --simulator \"iPhone 6 11.3\""
    }
    

    4) npm run start-iphone6

    0 讨论(0)
  • 2020-12-12 10:07

    There are multiple ways to achieve this:

    1. By using --simulator flag
    2. By using --udid flag

    Firstly you need to list all the available devices. To list all the devices run

    xcrun simctl list device
    

    This will give output as follows:

    These are the available devices for iOS 13.0 onwards:

    == Devices ==
    -- iOS 13.6 --
        iPhone 8 (5C7EF61D-6080-4065-9C6C-B213634408F2) (Shutdown) 
        iPhone 8 Plus (5A694E28-EF4D-4CDD-85DD-640764CAA25B) (Shutdown) 
        iPhone 11 (D6820D3A-875F-4CE0-B907-DAA060F60440) (Shutdown) 
        iPhone 11 Pro (B452E7A1-F21C-430E-98F0-B02F0C1065E1) (Shutdown) 
        iPhone 11 Pro Max (94973B5E-D986-44B1-8A80-116D1C54665B) (Shutdown) 
        iPhone SE (2nd generation) (90953319-BF9A-4C6E-8AB1-594394AD26CE) (Booted) 
        iPad Pro (9.7-inch) (9247BC07-00DB-4673-A353-46184F0B244E) (Shutdown) 
        iPad (7th generation) (3D5B855D-9093-453B-81EB-B45B7DBF0ADF) (Shutdown) 
        iPad Pro (11-inch) (2nd generation) (B3AA4C36-BFB9-4ED8-BF5A-E37CA38394F8) (Shutdown) 
        iPad Pro (12.9-inch) (4th generation) (DBC7B524-9C75-4C61-A568-B94DA0A9BCC4) (Shutdown) 
        iPad Air (3rd generation) (03E3FE18-AB46-481E-80A0-D37383ADCC2C) (Shutdown) 
    -- tvOS 13.4 --
        Apple TV (41579EEC-0E68-4D36-9F98-5822CD1A4104) (Shutdown) 
        Apple TV 4K (B168EF40-F2A4-4A91-B4B0-1F541201479B) (Shutdown) 
        Apple TV 4K (at 1080p) (D55F9086-A56E-4893-ACAD-579FB63C561E) (Shutdown) 
    -- watchOS 6.2 --
        Apple Watch Series 4 - 40mm (D4BA8A57-F9C1-4F55-B3E0-6042BA7C4ED4) (Shutdown) 
        Apple Watch Series 4 - 44mm (65D5593D-29B9-42CD-9417-FFDBAE9AED87) (Shutdown) 
        Apple Watch Series 5 - 40mm (1B73F8CC-9ECB-4018-A212-EED508A68AE3) (Shutdown) 
        Apple Watch Series 5 - 44mm (5922489B-5CF9-42CD-ACB0-B11FAF88562F) (Shutdown) 
    

    Then from the output you can select the name or the uuid then proceed as you wish.

    1. To run using --simulator run:
    npx react-native run-ios --simulator="iPhone SE"
    
    1. To run using --udid flag run:
    npx react-native run-ios --udid 90953319-BF9A-4C6E-8AB1-594394AD26CE
    

    I hope this answer helped you.

    0 讨论(0)
  • 2020-12-12 10:09

    Specify a simulator using the --simulator flag.

    These are the available devices for iOS 14.0 onwards:

    npx react-native run-ios --simulator="iPhone 8"
    npx react-native run-ios --simulator="iPhone 8 Plus"
    npx react-native run-ios --simulator="iPhone 11"
    npx react-native run-ios --simulator="iPhone 11 Pro"
    npx react-native run-ios --simulator="iPhone 11 Pro Max"
    npx react-native run-ios --simulator="iPhone SE (2nd generation)"
    npx react-native run-ios --simulator="iPhone 12 mini"
    npx react-native run-ios --simulator="iPhone 12"
    npx react-native run-ios --simulator="iPhone 12 Pro"
    npx react-native run-ios --simulator="iPhone 12 Pro Max"
    npx react-native run-ios --simulator="iPod touch (7th generation)"
    npx react-native run-ios --simulator="iPad Pro (9.7-inch)"
    npx react-native run-ios --simulator="iPad Pro (11-inch) (2nd generation)"
    npx react-native run-ios --simulator="iPad Pro (12.9-inch) (4th generation)"
    npx react-native run-ios --simulator="iPad (8th generation)"
    npx react-native run-ios --simulator="iPad Air (4th generation)"
    

    List all available iOS devices:

    xcrun simctl list devices
    

    There is currently no way to set a default.

    React Native Docs: Running On Simulator

    0 讨论(0)
  • 2020-12-12 10:16

    You can also use npm for this by adding an entry to the scripts element of your package.json file. E.g.

    "launch-ios": "react-native run-ios --simulator \"iPad Air 2\""
    

    Then to use this: npm run launch-ios

    0 讨论(0)
  • 2020-12-12 10:17

    If you want to change default device and only have to run react-native run-ios you can search in finder for keyword "runios" then open folder and fixed index.js file change 'iphone X' to your device in need.

    [1]: https://i.stack.imgur.com/BCtR1.png

    0 讨论(0)
  • 2020-12-12 10:18

    I developed CLI tool for it.You can just type "rndcli".and select device

    https://github.com/nazrdogan/rndcli

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