我正在开发一个 iphone 应用程序,当我处于开发的早期阶段时,我经常需要从模拟器中删除应用程序以重置应用程序的数据。当我清理源代码时,我想让 XCode 自动执行此操作,但我不确定如何执行此操作。
问问题
697 次
1 回答
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
于 2013-01-10T20:00:42.723 回答