Update on 2013-08-24: If you need a solution for Android, check out this post.
Update on 2013-06-09: I’ve updated the
plist_build_info.sh script so that it inserts the tag for the commit, if you’re not on a branch now.
It’s a very useful feature when the build process automatically stores the build info (e.g., date, time, git branch and commit hash), so that it can be read from your app in runtime.
It’s quite easy to do in Xcode, here’s a script for that:
1 2 3 4 5 6 7 8 9 10 11 12
Download it to the directory where your
.xcworkspace file is. Open the project/workspace in Xcode, (optional) add the script to the
Supporting Files group, but uncheck its target membership on the right:
Click the project on the left, then select your target,
Build Phases tab, click the
Add Build Phase button at the bottom, select
Add Run Script menuitem, (recommended) rename the added step to
'Save build info into info.plist', and set the command to
Don’t forget to open the app’s plist file (
YourProject-Info.plist) and add an empty row with key =
BuildTime and type =
To get the values, use like this:
1 2 3 4 5 6 7 8
For instance, show the build info in a view controller:
As an added benefit, in the Xcode’s Organizer you can click on
Applications of your device and look at the version of the app installed:
You can try this at home! :)