Running your project on an iOS simulator with React Native CLI is really easy if you are using a Mac, you just have to use the react-native run-ios command. Lately I’ve been checking things on the iPhone X a lot more(I recently wrote another article about SafeAreaView) so I find myself running projects on the iPhone X simulator. Specifying a simulator isn’t that hard with React Native CLI either, you just need to use the simulator flag, like this:
What About Setting a Default iOS Simulator?
To keep things short, it’s not actually strictly possible. The code that deals with the default simulator seems to be buried in the react-native module. You could change that but it seems like a kind of messy approach. I don’t know why it still hasn’t been changed from iPhone 6. We’re already past iPhone 8. Anyway, there’s a much better way of doing things…By adding a new script to your project’s package.json file.
What To Add
Your project’s package.json file should already have a couple of scripts specified, for start and test. All you need to do is add a new script that is somewhat descriptive. Here’s an example of the scripts for one of my recent projects:
You would use this with npm, like this:
This will start your project with the iPhone X simulator and it’s a lot shorter than using the –simulator flag like I explained above.
The same principal will work with physical devices too, physical device deployment has it’s own flag: device. I explained that in another article I wrote last year, if you’re interested you can read about it here.