Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script to install app in iOS Simulator

I am trying to automate the process of building an app, running unit tests, and finally running UI tests.

I am building the app via command line (xcodebuild -sdk iphonesimulator6.0) in some directory.

How do I install this app to the iOS simulator via command line (in ~/Library/Application Support/iPhone Simulator//Applications)?

I tried:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication MyApp.app/MyApp

but this opens a new finder window named "iOS Simulator could not find the application to simulate".

like image 807
stackErr Avatar asked Oct 18 '12 21:10

stackErr


1 Answers

I made a shell script which installs the app to the simulator.

#!/bin/sh
# Pick a uuid for the app (or reuse existing one).
if ! [ -f installApp.uuid ]; then
    uuidgen > installApp.uuid
fi
UUID=$(cat installApp.uuid)
#create supporting folders
TOPDIR="$HOME/Library/Application Support/\
iPhone Simulator/6.0/Applications/$UUID/"
mkdir -p "$TOPDIR"
mkdir -p "$TOPDIR/Documents"
mkdir -p "$TOPDIR/Library"
mkdir -p "$TOPDIR/tmp"
mkdir -p "$TOPDIR/$1.app"

#copy all the app file to the simulators directory
cp -r * "$TOPDIR/$1.app"

How to use this script to install the app:

  1. Change this line:

    TOPDIR="$HOME/Library/Application Support/iPhone Simulator/6.0/Applications/$UUID/"
    

    to reflect the version of iPhone Simulator you are using i.e. 6.0/7.1.

  2. Save the script as installApp.sh in your project_name.app/ folder.

  3. Open a terminal window and run installApp from the project directory.

    • So if I have my project_name.app/ with a project inside. Type in the terminal:

      cd path/to/project_name.app/

    • Then ./installApp to install the app to the simulator.

I got the idea from Jeffrey Scofield: Run iOS Simulator from the Command Line


For iOS8 and the new XCode Apple changed a few things and made it difficult to install apps via the command line. It is still possible to do:

  1. First you need to find the app directory (assuming you have installed apps): find ~/Library/Developer/CoreSimulator/Devices -name '*.app'

  2. This will list all the paths that have a custom app installed. E.g.

/34792D41-55A9-40F5-AAC5-16F742F1F3E4/data/Containers/Bundle/Application/4BA2A285-6902-45A8-9445-FC3E46601F51/YourApp.app

  1. There will be multiple UUID parent directories with the structure above. Each UUID corresponds to a simulator for a different device. Open the top directory and you will find a device.plist file. This file will contain the device it is simulating:
<dict>
    ...
    <string>34792D41-55A9-40F5-AAC5-16F742F1F3E4</string>
    <string>com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus</string>
    ...
</dict>
  1. If you want to install your app for iPhone-6-Plus this is the directory you would do it in. Run the shell script above to install the app. Change the TOPDIR path to $HOME/Library/Developer/CoreSimulator/Devices/{UUID for device}/data/Containers/Bundle/Applications/$UUID/
like image 87
stackErr Avatar answered Oct 27 '22 00:10

stackErr