学科:IOS/Xcode/build script

来自维基学院

把TODO,FIXME等注释转化为编译结果中的警告[编辑 | 编辑源代码]

#!/bin/sh
# 把TODO,FIXME等注释转化为编译结果中的警告
# by Kellen Styler
# via: http://d3signerd.com/turn-fixme-todo-and-comments-into-compiler-warnings/
KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"


编译时自增构建数[编辑 | 编辑源代码]

参考:

下面是使用Plistbuddy的增强版,增加了只在文件修改时自增

#!/bin/sh
# 自增构建数
# via: http://stackoverflow.com/q/9258344

plist=${PROJECT_DIR}/${INFOPLIST_FILE}
dir="$(dirname "$plist")"

# 仅当文件有修改时自增
if [ -n "$(find "$dir" \! -path "*xcuserdata*" \! -path "*.git" -newer "$plist")" ]; then
    buildnum=$(/usr/libexec/Plistbuddy -c "Print CFBundleVersion" "$plist")
    if [ -z "$buildnum" ]; then
        echo "No build number in $plist"
        exit 2
    fi
    buildnum=$(expr $buildnum + 1)
    # 或使用日期(形如:121204):
    # buildnum=$(date "+%y%m%d")
    /usr/libexec/Plistbuddy -c "Set CFBundleVersion $buildnum" "$plist"
    echo "Incremented build number to $buildnum"
else
    echo "Not incrementing build number as source files have not changed"
fi

APP to IPA[编辑 | 编辑源代码]

把现有App包转换为IPA可以创建一个服务,这样可以在finder中直接选择一个app,然后使用服务直接完成转换。

你需要创建一个Automator服务,设置该服务可以接受文件,下面的脚本就是用来处理接受文件的。

#!/bin/sh
# App转IPA包,Automator shell脚本
source=$*
dateID=$( date +%j )
target=${source%.*}-${dateID}.ipa
#echo $source
#echo $target
xcrun -sdk iphoneos PackageApplication -v "$source" -o "$target"

参考: Generating ipa from xcode command-line - Stack Overflow

正常在Xcode中生成IPA的话,Archive后选择Ad Hoc或In House方式的Distribute即可。

将项目目录中的所有文件按字母顺序排序[编辑 | 编辑源代码]

使用xUnique脚本:https://github.com/truebit/xUnique

假设脚本文件在 $(SRCROOT)/Scripts/xUnique.py

# 项目按字母排序
cd Scripts
python2 xUnique.py $PROJECT_FILE_PATH

在应用Icon上加入版本信息[编辑 | 编辑源代码]

见: Overlaying Application Version on Top of Your Icon http://www.merowing.info/2013/03/overlaying-application-version-on-top-of-your-icon/


参考[编辑 | 编辑源代码]