如果需要xcode自动打包多个渠道的ipa,那么只需要去修改plist文件 使用applescript和shell方法就能解决当前的问题。
把下边的代码copy到文件保存成sh文件,命名为ipa-build,你可以根据自己的需要修改代码 在terminal中执行下边语句
ipa-build par1 par2 其中ipa-build必须得绝对路径,par1是必须得,par2是可选的
比如在我自己的电脑上: /Users/mac/Henry/IOS/xcode_shell-master/ipa-build /Users/mac/Henry/IOS/managerpro/trunk/YddManagerPro Distribution #!/bin/bash CHANNELID=(“V1” “V2”) for ((i=0;i<${#CHANNELID[@]};i++)) #for ((i=0;i<3;i++)) do
if [ $# -lt 1 ];then echo "Error! Should enter the root directory of xcode project after the ipa-build command." exit 2 fi
if [ ! -d $1 ];then echo "Error! The first param must be a directory." exit 2 fi
#工程绝对路径 cd $1 project_path=$(pwd)
#编译的configuration,默认为Release build_config=Release
param_pattern=":nc:o:t:ws:" OPTIND=2 while getopts $param_pattern optname
should_clean=y
tmp_optind=$OPTIND tmp_optname=$optname tmp_optarg=$OPTARG OPTIND=$OPTIND-1 if getopts $param_pattern optname ;then
echo exit 2 fi OPTIND=$tmp_optind
build_config=$tmp_optarg
tmp_optind=$OPTIND tmp_optname=$optname tmp_optarg=$OPTARG
OPTIND=$OPTIND-1 if getopts $param_pattern optname ;then
echo exit 2 fi OPTIND=$tmp_optind
cd $tmp_optarg output_path=$(pwd) if [ ! -d $output_path ];then echo "Error!The value of option o must be an exist directory." exit 2 fi
workspace_name='*.xcworkspace' ls $project_path/$workspace_name &>/dev/null rtnValue=$? if [ $rtnValue = 0 ];then build_workspace=$(echo $(basename $project_path/$workspace_name)) else
echo exit 2 fi
tmp_optind=$OPTIND tmp_optname=$optname tmp_optarg=$OPTARG
OPTIND=$OPTIND-1 if getopts $param_pattern optname ;then
echo exit 2 fi OPTIND=$tmp_optind
build_scheme=$tmp_optarg
tmp_optind=$OPTIND tmp_optname=$optname tmp_optarg=$OPTARG
OPTIND=$OPTIND-1 if getopts $param_pattern optname ;then
echo exit 2 fi OPTIND=$tmp_optind
build_target=$tmp_optarg
exit 2
exit 2
exit 2
#build文件夹路径 build_path=${project_path}/build #生成的app文件目录 appdirname=Release-iphoneos if [ $build_config = Debug ];then appdirname=Debug-iphoneos fi if [ $build_config = Distribute ];then appdirname=Distribute-iphoneos fi #编译后文件路径(仅当编译workspace时才会用到) compiled_path=${build_path}/${appdirname}
#是否clean if [ "$should_clean" = "y" ];then xcodebuild clean fi
xcodebuild clean
#组合编译命令 build_cmd='xcodebuild'
if [ "$build_workspace" != "" ];then #编译workspace if [ "$build_scheme" = "" ];then echo "Error! Must provide a scheme by -s option together when using -w option to compile a workspace." exit 2 fi
build_cmd=${build_cmd}' -workspace '${build_workspace}' -scheme '${build_scheme}' -configuration '${build_config}' CONFIGURATION_BUILD_DIR='${compiled_path}' ONLY_ACTIVE_ARCH=NO'
else #编译project build_cmd=${build_cmd}' -configuration '${build_config}
if [ "$build_target" != "" ];then build_cmd=${build_cmd}' -target '${build_target} fi
fi
#编译工程 cd $project_path
#app文件名称 appname=$(basename ./${appdirname}/*.app)
#app文件中Info.plist文件路径 app_infoplist_path=${build_path}/${appdirname}/${appname}/Info.plist
#更新项目plist文件 updateplist= $(/usr/libexec/PlistBuddy -c "set :HenryTest ${CHANNELID[$i]}" /Users/mac/Henry/IOS/managerpro/trunk/YddManagerPro/YddManager/YddManager-Info.plist)
$build_cmd || exit
#进入build路径 cd $build_path
#创建ipa-build文件夹 #if [ -d ./ipa-build ];then # rm -rf ipa-build #fi mkdir ipa-build
#取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print
CFBundleShortVersionStri #取build值 bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" ${app_infoplist_path}) #通过app文件名获得工程target名字 target_name=$(echo $appname | awk -F. '{print $1}') #IPA名称 #ipa_name="${target_name}_${bundleShortVersion}_${build_config}${bundleVersion}_$(date +"%Y%m%d")" ipa_name="${bundleShortVersion}_${build_config}${bundleVersion}_${CHANNELID[$i]}"
#xcrun打包 xcrun -sdk iphoneos PackageApplication -v ./${appdirname}/*.app -o ${build_path}/ipa-build/${ipa_name}.ipa || exit
if [ "$output_path" != "" ];then cp ${build_path}/ipa-build/${ipa_name}.ipa $output_path/${ipa_name}.ipa echo "Copy ipa file successfully to the path $output_path/${ipa_name}.ipa" fi
done
你可以可以参考学习:http://www./Program/IOS/201309/148887.shtml |
|