While developing application we keep sharing the builds with others. It is very difficult to find out which version they are using and the date it was build. To overcome this I was searching for methods that can used to auto increment build numbers and set the application build date. I found this article really useful.

Incrementing Build Numbers in Xcode

To that script I made few changes to suit my needs.

#!/bin/bash
# Auto Increment Version Script
buildPlist="Project-Info.plist"
CFBuildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBuildNumber" $buildPlist)
CFBuildNumber=$(($CFBuildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBuildNumber $CFBuildNumber" $buildPlist
CFBuildDate=$(date)
/usr/libexec/PlistBuddy -c "Set :CFBuildDate $CFBuildDate" $buildPlist

Please make sure you have added two variables “CFBuildNumber” and “CFBuildDate” in Project-Info.plist

You can access the version information using the following code

NSString * version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
NSString * buildNo = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBuildNumber"];
NSString * buildDate = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBuildDate"];
NSLog(@"Application Version: %@ Build No: %@ Build Date: %@",version,buildNo,buildDate);

Hope this helps 😉