Xcode打开项目勾选自动签名,设置Team和Bundle Identifier
等待Xcode自动下载安装Certificates和Provisioning Profile
确认mac里已经安装开发者证书Certificates和Provisioning Profile
打开[钥匙串访问>登陆>我的证书>Apple Development...]获取组织单位(teamID)
将下面代码保存为shell文件,修改配置参数后,放到项目根目录执行
# 配置打包参数
workspace="配置workspace文件名(project_name.xcworkspace)"
scheme="配置项目target名称(target_name)"
teamID="配置teamID"
# 配置上传参数
user="配置Apple ID"
pass="配置App-Specific Passwords"
# 清理项目
project_path=$(cd `dirname $0`; pwd)
cd $project_path
xcodebuild clean -workspace $workspace -scheme $scheme
# 创建xcarchive
archiveFilename=(`date +%Y_%m_%d_%H_%M_%S`)
package_dir="package"
mkdir $package_dir
archivePath="$project_path/$package_dir/$archiveFilename"
xcodebuild archive -workspace $workspace -scheme $scheme -archivePath $archivePath -configuration Release
# 创建ipa
cd $package_dir
exportOptionsPlist="ExportOptions.plist"
echo "<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>generateAppStoreInformation</key>
<false/>
<key>manageAppVersionAndBuildNumber</key>
<true/>
<key>method</key>
<string>app-store</string>
<key>signingStyle</key>
<string>automatic</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>$teamID</string>
<key>uploadSymbols</key>
<true/>
</dict>
</plist>
" > ${exportOptionsPlist}
xcodebuild -exportArchive -archivePath "$archivePath.xcarchive" -exportPath $archivePath -exportOptionsPlist $exportOptionsPlist
# 上传ipa
xcrun altool --upload-app -t ios -f $archivePath/*.ipa -u $user -p $pass