How to Run iOS in React Native
We will introduce how to run iOS in React Native and change the default simulator for iOS.
Run iOS in React Native
When making changes to our already developed app, adding new features, or developing a new application, we need to see how our code displays results. React Native gives us the option to run our under-development app using a simple command in CLI.
We can even run our React Native application on Android
or iOS
using this command. We can even use the simulator to view our application on different Android or iOS devices.
We will install expo-cli
using the npm
command.
# react native
npm install -g expo-cli
If you use yarn
instead of npm
, you can use the following command.
# react native
yarn global add expo-cli
Now we will create a new React Native project using the expo
command.
# react native
expo init MyApp
This command will create a new project, MyApp
. This command will work on npm
and yarn
users. We will go into our project directory and start the app using the npm
command.
# react native
cd MyApp
npm start
If you are using yarn
.
# react native
cd MyApp
yarn start
We can also start our app by running the expo
command.
# react native
cd MyApp
expo start
Once we have created our new React Native application, we can even use a simulator to run our app on any Android or iOS version or connect our phone to run our app. But in this tutorial, we will use the simulator to run our application on different versions of the iOS device.
We can use --simulator
in our command to run our application in the desired iOS version available in the simulator.
Using the following command, let’s run our application on iPhone 11
.
# react native
npx react-native run-ios --simulator="iPhone 11"
This command will run our newly created React Native application on iPhone 11
. If we like to check which devices are available in the simulator, we can run the following command.
# react native
xcrun simctl list devices
We can also define our custom commands using npm
. We will add a launch-app
command to the scripts
in the package.json
file.
# react native
"launch-app": "react-native run-ios --simulator \"iPhone 11\""
We can use this command to always run our application on iPhone 11
using npm
.
# react native
npm run launch-app
In this way, we can easily run our application in any iOS version we want using the simulator and some easy commands in React Native.
Rana is a computer science graduate passionate about helping people to build and diagnose scalable web application problems and problems developers face across the full-stack.
LinkedIn