cat /dev/brain > blog

yet another weblog – by Sven A. Schmidt

Integrating git version info in iOS/Cocoa apps

leave a comment »

This is a quick reminder on how to add version info from git to your Xcode application – iOS or Cocoa – so you can see in the actual application which repository state this binary was built from.

There’s nothing new in this post really – others have done the same and blogged about it – but it serves as a note to self on how to quickly go about it and, as such, may be helpful to others. It’s really a quite simple two step process:

  1. Add a script build phase to your build target (at the end, after the other build steps):

    git status
    version=$(git describe --tags --dirty)
    echo version: $version
    info_plist=$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Info.plist
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $version" $info_plist

    The extra command git status to refresh the index was added, because sometimes the repos would be reported as dirty otherwise. Not sure why exactly it’s happening but this is the fix. Maybe it’s some temporary build file.

  2. Add a UILabel to one of your views (or simply NSLog to the console) and show the version:

    - (void)viewDidLoad {
    ...
    NSString *version = [[[NSBundle mainBundle] infoDictionary]
    objectForKey:@"CFBundleVersion"];
    self.versionLabel.text = version;
    }

Advertisement

Written by sas

December 29, 2010 at 15:12

Posted in iphone, osx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: