Sh*t my brain says and forgets about

iOS – Pull App Version From Bundle Configuration

We all like to put the current application version number in an “about” screen somewhere for users to reference.  It’s a pain, however, to have to update that screen every time we do a release as well as the version in the target configuration for the bundle.  So why not pull the version number from the bundle?  Here’s how to do it:
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];

NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

Just put this version number in your label programatically and you’re set!  Since my About screen is in a nib/xib, I set the label text to “Version x.x” so I would understand the label isn’t static next time I look at the screen in Interface Builder.

— UPDATED 3/9/2012

I updated this post with a recent change to the way version numbers work.  Not sure if this was an advertised change by Apple, but this should fix any issues you have.

Previous

Time Warner Cable Power / SNR Acceptable Values

Next

iOS – Customize Table View Cells

4 Comments

  1. Thanks for this, just what I needed!

  2. Stephen

    Thanks Aaron – very handy. 🙂

  3. Tim

    This does not work for me. It returns the Build number NOT the version number.

    If I use the code provided and my app is Version 1.0 Build 56 I get “56” returned, not “1.0” this happens on both iOS 4.3 and 5.x

  4. Aaron

    I forgot to update this post – try this –

    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@”CFBundleShortVersionString”];
    NSString *versionLabelText = [NSString stringWithFormat:@”Version %@”, version];

Leave a Reply to John Cancel reply

Your email address will not be published. Required fields are marked *

Powered by WordPress & Theme by Anders Norén