Skip to content

Instantly share code, notes, and snippets.

@joshbuhler
Last active December 15, 2015 21:09
Show Gist options
  • Save joshbuhler/5323194 to your computer and use it in GitHub Desktop.
Save joshbuhler/5323194 to your computer and use it in GitHub Desktop.
This will automatically bump the build number of your project's info.plist file when creating an archive for distribution of your app. To use, add this script as a "Run Script" phase to your Xcode build phases, *before* the "Copy Bundle Resources" phase. (It needs to be here so that the updated info.plist file will be copied into the new archive…
#!/bin/bash
##################################################
#
# BuildVersion incrementing script v1.0
#
##################################################
processedPlist="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
projectPlist="${INFOPLIST_FILE}"
versionVar="CFBundleVersion"
buildNumber=$(/usr/libexec/PlistBuddy -c "Print ${versionVar}" "${projectPlist}" 2>&1)
if [[ "$buildNumber" == *Does\ Not\ Exist ]] ; then
buildNumber=1
echo "Create ${versionVar} and set to ${buildNumber}"
/usr/libexec/PlistBuddy -c "Add :${versionVar} String ${buildNumber}" "${processedPlist}"
/usr/libexec/PlistBuddy -c "Add :${versionVar} String ${buildNumber}" "${projectPlist}"
else
buildNumber=$(($buildNumber + 1))
echo "set ${versionVar} to ${buildNumber}"
/usr/libexec/PlistBuddy -c "Set :${versionVar} ${buildNumber}" "${processedPlist}"
/usr/libexec/PlistBuddy -c "Set :${versionVar} ${buildNumber}" "${projectPlist}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment