0

When running a react native application the device simulator for some reason always defaults to iPhone 6, part of the output:

$ react-native run-ios
Found Xcode project AwesomeProject.xcodeproj
Launching iPhone 6 (9.3)...

The device can be changed only through Hardware>Device menu once the simulator is running.

I have set up Xcode to use an older iPhone version inside the simulator, but it works only inside the IDE and not in CLI.

How to change the default iOS device when running through react-native in CLI?

1

3 Answers 3

1

Currently there seems no way to set the default. You can use this

react-native run-ios --simulator="iPhone 5"

to run on the custom simualtor as discussed in this thread.

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

Comments

0

It is possible to set default value by changing this file:

node_modules/react-native/local-cli/runIOS/runIOS.js

This block is useful for setting iOS simulator, Xcode scheme and root project location:

const args = parseCommandLine([
    {
      command: 'simulator',
      description: 'Explicitly set simulator to use',
      type: 'string',
      required: false,
      default: 'iPhone 6',
    }, {
      command: 'scheme',
      description: 'Explicitly set Xcode scheme to use',
      type: 'string',
      required: false,
    }, {
      command: 'project-path',
      description: 'Path relative to project root where the Xcode project (.xcodeproj) lives. The default is \'ios\'.',
      type: 'string',
      required: false,
      default: 'ios',
    }
  ], argv);

Comments

0

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

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

enter image description here

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

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.