在进行干净构建时,如何让XCode从模拟器中删除应用程序?

时间:2013-01-08 19:22:00

标签: ios xcode

我正在开发一款iphone应用程序,当我处于开发的早期阶段时,我经常需要从模拟器中删除应用程序以重置应用程序的数据。我想在清理源代码时让XCode自动执行此操作,但我不知道如何执行此操作。

1 个答案:

答案 0 :(得分:3)

Yeah Right Keller的这篇文章的帮助下,我想出了如何做到这一点。将外部构建脚本设置为项目的依赖项,可以在清理项目时运行脚本。

由于那篇文章已经过时,我为XCode 4.5编写了新的说明。 http://nerglish.tumblr.com/post/40191311173/delete-app-from-simulator-when-cleaning-in-xcode

这是我写的从模拟器中删除应用程序的脚本

#!/bin/bash

# DeleteApp.sh
#
# Deletes iPhone app from the iOS Simulator when called with the clean action
#

APP_NAME="$PROJECT_NAME.app"

buildAction () {
echo "Building..."

# Don't do anything when building

}

cleanAction () {
echo "Cleaning..."

echo "Killing iPhone Simulator"
killall "iPhone Simulator"

# Change IFS to preserve spaces in the paths
IFS=$(echo -en "\n\b")
for appDir in $(find "/Users/$USER/Library/Application Support/iPhone Simulator"/*/Applications -name "$APP_NAME")
do
    dir=$(dirname "$appDir")
    echo "Deleting $dir"
    rm -rf "$dir"
done
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# MAIN

echo "Running with ACTION=${ACTION}"

case $ACTION in
# NOTE: for some reason, it gets set to "" rather than "build" when
# doing a build.
"")
buildAction
;;

"clean")
cleanAction
;;
esac

exit 0