I created a script that I can drop into any Xcode project folder and call from a Run Script which will update the Info.plist for the app and the dSYM so that the build number matches. It can then be uploaded to services like HockeyApp and iTunes Connect for TestFlight and the App Store.
I prefer to manage the script outside of Xcode's Run Script because I can edit it more easily and keep the contents of the project file much smaller. I can also version control the script independently of the project file.
The Build Number in this script is set with just the current date. There are other ways to generate a unique build number. One approach is covered on Jared Sinclair's blog which uses the Git hash for the latest commit. The script I am using uses a timestamp which goes down to a minute. I find it useful to know when a build was created and having the build number double as a timestamp I can see the date immediately. And for my purposes it is unique enough.
http://blog.jaredsinclair.com/post/97193356620/the-best-of-all-possible-xcode-automated-build
Gist: https://gist.github.com/brennanMKE/c4640b7a2cf39888d858
#!/bin/sh
set -e
# Purpose: Updates Info.plist for app and dSYM to a unique value for each build.
# Usage:
# Add as a Run Script in Xcode Build Phases
# UPDATE_SCRIPT=${PROJECT_DIR}/update_build_number.sh
# if [ -f ${UPDATE_SCRIPT} ]; then
# sh ${UPDATE_SCRIPT}
# fi
BUILD_NUMBER=`date "+%Y.%m.%d.%H%M"`
APP_INFO_PLIST=${TARGET_BUILD_DIR}/${INFOPLIST_PATH}
DSYM_INFO_PLIST=${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Info.plist
if [ -f ${APP_INFO_PLIST} ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "${APP_INFO_PLIST}"
echo "Updated ${APP_INFO_PLIST}"
else
echo "Could not find ${APP_INFO_PLIST}"
fi
# Only the Release Configuration creates the dSYM
if [ "${CONFIGURATION}" = 'Release' ]; then
if [ -f ${DSYM_INFO_PLIST} ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "${DSYM_INFO_PLIST}"
echo "Updated ${DSYM_INFO_PLIST}"
else
echo "Could not find ${DSYM_INFO_PLIST}"
fi
fi