ios-simulatorexpo

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.)


Solution

  • 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:

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

    demo of multiple iOS simulators