Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running multiple iOS simulators with React Native?

Tags:

react-native

I want to run the app in multiple IOS simulators with React Native so will be able to compare the iPhone version vs the iPad version

I see there is some one already did it https://ashleyd.ws/running-multiple-ios-simulators-with-react-native/

but unfortunate he did not mention how he did it

like image 669
Abdullah Almesbahi Avatar asked Jun 29 '16 12:06

Abdullah Almesbahi


People also ask

Which iOS simulator to use for React Native?

You can specify the device the simulator should run with the --simulator flag, followed by the device name as a string. The default is "iPhone 13" . If you wish to run your app on an iPhone SE (2nd generation), run npx react-native run-ios --simulator='iPhone SE (2nd generation)' .

How do I run an iOS app in React Native?

Open your react native app's directory, navigate to ios folder, and double-click on . xcworkspace file to open the Xcode. Next, open the Product menu, go to Destination, and select your device. If you don't have an Apple Developer account, you must create one to be able to run your project on an iOS device.

Can Xcode run React Native?

If you are already familiar with mobile development, you may want to use React Native CLI. It requires Xcode or Android Studio to get started. If you already have one of these tools installed, you should be able to get up and running within a few minutes.


5 Answers

Using MacOs Terminal, launch first simulator:

  1. cd /Applications/Xcode.app/Contents/Developer/Applications
  2. open -n Simulator.app
  3. cd <your react native project>
  4. react-native run-ios

Now, launch 2nd simulator:

  1. cd /Applications/Xcode.app/Contents/Developer/Applications
  2. open -n Simulator.app
  3. Click "Ok" when you get "Unable to boot device in current state"
  4. Change simulator to be different than first simulator (e.g. Hardware -> Device -> iPhone 6s)
  5. cd <react-native project>
  6. react-native run-ios --simulator "iPhone 6s" (or whatever simulator you chose in step 8).

Note: In the last step, you can disregard the terminal output since it indicates that it is launching using the 1st simulator hardware. In fact, it is launching into the 2nd simulator (as desired).

like image 90
Wookiem Avatar answered Oct 19 '22 20:10

Wookiem


I got two separate react native apps running at the same time doing this

I entered the following in one terminal for the first app

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

After that finished building I opened another terminal and ran for the second app

react-native run-ios --simulator="iPhone XS" --port=8088

Then that built the second app on the new simulator and using a different port for the metro bundler. However after the second one built the first app changed its screen from the first app to the second app. I hit the home button and just re-opened the first app. One observation is that the first app seems to have both apps installed in the simulator while the second one does not.

like image 42
Jose Avatar answered Oct 19 '22 20:10

Jose


This isn't the direct answer to your question, but I think it gives a better solution than running different simulators. You can check the following lib called ScreenSwitcher.

It basically use the same simulator, in our case iPhone 6 plus only and you can check and inspect any other smaller screen on it directly. I find that approach more efficient and faster.

ScreenSwitcher

like image 41
Mohamed Saleh Avatar answered Oct 19 '22 20:10

Mohamed Saleh


Opening multiple simulators from the command-line did not work for me. With some manual interaction I got this to work with simulator 10.0 and react-native 0.47.2 - its based on the fact that react native always opens the app in the last opened simulator:

  • manually open simulator
  • start app: react-native run-ios
  • manually do: Hardware -> Device -> select iOS -> select Device (different then before !)
  • that will open a second simulator
  • start app again: react-native run-ios
  • this opens the app in the second simulator
like image 24
Gijs Avatar answered Oct 19 '22 21:10

Gijs


I have Used more than 2 Simulator at a one time by using different terminals and they works well 

react-native run-ios --simulator="iPhone 11 Pro Max"  //write like this.
react-native run-ios --simulator="iPhone 6".          //write like this.
react-native run-ios --simulator="iPhone 12 Pro Max"  //write like this.
react-native run-ios --simulator="iPhone 8 Plus".    
like image 1
sherkhan Avatar answered Oct 19 '22 19:10

sherkhan