Build iOS application and upload to App Store from command line

Currently I am investigate how to build the iOS application from command line, this article is what I have done right now.

Build iOS application and upload to App Store from command line

Currently I am investigate how to build the iOS application from command line, this article is what I have done right now.

Build application and generate xcarchive filexcodebuild -workspace <project>.xcworkspace \
   -scheme <schema name> \
   -configuration 'Release' \
   -sdk iphoneos \
   archive -archivePath ${PWD}/build/<project>.xcarchive

Replace the project name and schema name with your project information, my project works with cocoapods, so I build the project with the xcworkspace, the generated xcarchive will be located under build directory.

Upload application to App Storexcodebuild -exportArchive \
   -archivePath ${PWD}/build/<project>.xcarchive \
   -exportOptionsPlist exportOption.plist \
   -exportPath ${PWD}/build

The command above can export ipa file or upload the application to the App Store, it depends on the content of the exportOption.plist file.

Upload to App Store

The content below is the content of the exportOptions.plist , with this options, the xcodebuild command will upload the application to the App Store.<?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>method</key>
   <string>app-store</string>
   <key>destination</key>
   <string>upload</string>
</dict>
</plist>

Export to ipa file

The content below of the file exportOptions.plist will export the archive to an ipa file, just change the destination to export.<?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>method</key>
   <string>app-store</string>
   <key>destination</key>
   <string>export</string>
</dict>
</plist>

The problem that still exists

When I run exportArchive command, it will ask me to input the password to get the information from keychain, I select ‘Always Allow’, and it reports the following error:IDEDistribution: Failed to log in with account "<apple id>" while checking for an App Store Connect account
error: exportArchive: Failed to log in.

I delete the account from xcode and login again, and input the password every time, it can upload successfully, I still need to investigate the problem again.