Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I run my Expo app on multiple iOS Simulators at once?

Is it possible to run an Expo app on multiple versions of iOS Simulator at once? It would be really nice to have two or three iPhones refreshing automatically, so that it's easy to tests the layout with different screen sizes.

(I know I can do this with multiple hardware devices, and I know that I can change was device iOS Simulator should use.)

like image 725
Jan Aagaard Avatar asked Dec 25 '18 19:12

Jan Aagaard


People also ask

How do I run multiple simulators?

I personally prefer to use a Multiple Simulators as the trigger simulator. For creating a new simulator, just hit cmd + shift + 2 to open the devices window then select Simulators then name it whatever you want but remember it because it will be used later. I'll call it Multiple Simulators.

How do I run two simulators in Xcode?

If you require a different version of the iOS simulator than is provided by your Xcode installation, you can download additional simulators in Xcode. Open Xcode and click Menu > Xcode > Preferences > Select Components, and then choose the simulator version you want to download.

How do you run the Expo app in Simulation?

Start your app by using expo start command. Type i and a or click on Run on iOS simulator and Run on Android device/emulator buttons to launch your app on devices.


2 Answers

This command:

expo-cli ios

does not let you choose the actual simulator on which it should run.

Assuming the Expo viewer app is installed and default ports are used, this command allows you to open it on a specific simulator:

xcrun simctl openurl <some-device-id> exp://127.0.0.1:19000

Run Expo on Multiple Simulators

It can be run on multiple simulators at once.

Since it's a bit cumbersome to restart the selected simulators from scratch every day, here's a small shell script that automatically starts three specific simulators based on their device IDs and opens the Expo application on them:

#!/bin/bash
declare -a simulators=("0FAE2F92-9EF7-4C4A-8F9D-097A056F8CC0" "BFCDD662-E4DE-4C08-9DF6-CAACA7C00CEC" "1A6959A0-C10F-474B-96C5-7E8955FBDD80")

for i in "${simulators[@]}"
do
    xcrun instruments -w $i
    #xcrun simctl install $i ~/.expo/ios-simulator-app-cache/Exponent-2.14.0.app
    xcrun simctl openurl $i exp://127.0.0.1:19000      
done

Here you can see three different simulator device IDs in an array. Of course you have to use your own device IDs of the simulators you want to use.

BTW: if you once installed the Exponent-x.x.x.app it is available in a hidden folder in your home directory. So by calling:

xcrun simctl install <some-device-id> ~/.expo/ios-simulator-app-cache/Exponent-2.14.0.app

you can even install the Expo app in a specific simulator (see also the commented line in the shell script above) from the command line.

NOTE: The Exponent-2.14.0.app version will change as the Expo SDK is upgraded. Exponent-2.14.0.app comes with expo-cli --version 3.13.1, which is current as of February 22, 2020.

How to Determine the Simulator IDs

xcrun simctl list

This displays the corresponding device ID for each simulator.

A small note: Over time, there are several simulator entries that are no longer available after an upgrade. To remove them with a simple command, proceed as follows:

xcrun simctl delete unavailable

Demo

Here is a short demo of the script:

  • three simulators are started
  • the Expo app is opened

The source code of the demo app is then changed. All three simulators are updated at once.

demo of multiple iOS simulators

like image 69
Stephan Schlecht Avatar answered Dec 02 '22 19:12

Stephan Schlecht


The accepted answer does not work in 2021 as "instruments" is not available in Xcode 13 anymore.

Please follow the instruction below:

Replace the device IDs with your device IDs xcrun simctl list. Also, replace the Expo version with what you have on your machine.

#!/bin/zsh
declare -a simulators=("27D6B718-8348-4C4D-ADFC-6506C2A88EED" "531A59B8-6197-4620-904B-E55308D1EE96" "C08532FE-3CE4-4BB7-A04C-795F2FA7EFE1")
echo "STARTED"
open -a Simulator
wait_time=1
for i in $simulators[@]
do
    echo "Boot $i"
    xcrun simctl boot $i
    sleep $wait_time
    echo "Install Expo $i"
    xcrun simctl install $i ~/.expo/ios-simulator-app-cache/Exponent-2.19.6.tar.app
    sleep $wait_time
    echo "Lauch Expo $i"
    xcrun simctl openurl $i exp://127.0.0.1:19000
    sleep $wait_time
done
echo "FINISHED"
like image 36
Fred A Avatar answered Dec 02 '22 19:12

Fred A