1

I want both the version numbers (CFBundleVersion and CFBundleShortVersionString) in Xcode 5 to be automatically set to the current date-time in UTC time zone every time I do a build.

For example, 201405041942 means May 4, 2014 at 7:42 PM UTC.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154

1 Answers1

9

Automate Setting Version Numbers

You can tell Xcode 5 on Mountain Lion or Mavericks to execute a tiny bash (Unix) script on each build to automatically set your two version numbers.

In the Xcode project > Build Phases > Run Script

(1) Set "Shell" to:

/bin/sh

(2) Set the bash script field to:

#!/bin/bash
buildNumber=$(date -u "+%Y%m%d%H%M")
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $buildNumber" "$INFOPLIST_FILE"

For the checkboxes, mine are set to…

• Check the box "Show environment variables in build log

• Uncheck the box "Run script only when installing".

screen shot of Xcode project > Build Phases > Run Script

After a build, you can verify the version numbers in Xcode project > General > Identity.

screen shot of Xcode project > General > Identity

Third Version Number

Be aware that your app's record on Apple's iTunesConnect web site defines a version number. If that number fails to match either CFBundleVersion or CFBundleShortVersionString you will get a warning. That warning may be ignored as it is not a show-stopping error.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154