Reputation: 743
Im writing an automated test that will use the Instruments automator to run a series of UX tests on my application. The problem is, I need the app to run on a fresh install for the specific set of tests that I am running. Is there a way to delete an app in the simulator through the command line?
Specifically, I am looking for something like this:
xcodeBuild -delete myApp.app
Upvotes: 1
Views: 2757
Reputation: 1502
Assuming you know the iOS version and the name of the app, this is a script I put together to remove a single app. It comes in handy if you don't want to reset the entire simulator and lose all other installed apps.
The script below is part of a larger script I use, but should work as shown. I've got this saved as simulator-uninstall.sh, you can then uninstall an app using something like:
./simulator-uninstall.sh ios=7.1 app="My App"
Here's the script (note, bash is not my strong point, but this worked for me!):
#!/bin/bash
for p in "$@"; do
# Parse out each param which needs to be of the form key=value
# Then remove any quotes around the value, because we will quote all vars anyway
IFS="=" read argkey argvalue <<< "$p"
argvalue="${argvalue%\"}"
argvalue="${argvalue#\"}"
case $argkey in
ios) IOS_VERSION=$argvalue
;;
app) APP_NAME=$argvalue
;;
esac
done
SIMULATOR_ROOT="$HOME/Library/Application Support/iPhone Simulator/$IOS_VERSION"
# Find the *.app directory
APP_PATH=`find "$SIMULATOR_ROOT/Applications" -name "$APP_NAME.app"`
if [ "$APP_PATH" ]; then
# Ensure simulator isn't running whilst we remove the app
killall "iPhone Simulator"
# Get the parent directory - this will be a UUID, then remove it
APP_DIR=`dirname "$APP_PATH"`
rm -rf "$APP_DIR"
echo "Removed $APP_DIR"
else
echo "App $APP_NAME not found for platform version $IOS_VERSION"
fi
Hope that helps!
Upvotes: 0
Reputation: 743
I actually ended up using the solution found here: https://stackoverflow.com/a/5128616/608739
The apple script works great and gets around all those pesky simulator issues.
--------------- OLD POST -------------------
Using jpancoast's lead, I modified his script to find and clear the latest version of the app on simulator:
CURRENT_SDK=""
if [ -z "$RUN_ON_SPECIFIC_DEVICE_OPTION" ] ; then
CURRENT_SDK=$(xcodebuild -showsdks | grep 'iphoneos[0-9].[0-9]' | grep -o '[0-9].[0-9]' | head -n1)
else
CURRENT_SDK=$(xcodebuild -showsdks | grep 'iphonesimulator[0-9].[0-9]' | grep -o '[0-9].[0-9]' | head -n1)
fi
rm -rf ~/Library/Application\ Support/iPhone\ Simulator/"$CURRENT_SDK"/Applications/*
The script checks to see if we are currently running on device or not. It then finds the folder corresponding to the latest SDK (assuming your project is building on that SDK) and deletes all applications associated with that SDK version. Further refinement can be made to only delete specific apps you are interested in.
Upvotes: 0
Reputation: 521
Something like this might work, although I haven't fully tested it:
rm -rf ~/Library/Application\ Support/iPhone\ Simulator/6.0/Applications/*
Substitute the proper simulator version number for the 6.0 of course.
Upvotes: 2