Thursday, March 24, 2011

How can my iphone app detect it's own version number?

I'm writing an iPhone app. It's already been published, but I would like to add a feature where it's version number is displayed.

I'd rather not have to do this manually with each version I release..

Is there a way in objective C to find out what the version is of my app?

From stackoverflow
  • This is a good thing to handle with a revision control system. That way when you get a bug report from a user, you can check out that revision of code and (hopefully) reproduce the bug running the exact same code as the user.

    The idea is that every time you do a build, you will run a script that gets the current revision number of your code and updates a file within your project (usually with some form of token replacement). You can then write an error handling routine that always includes the revision number in the error output, or you can display it on an "About" page.

  • You can specify the CFBundleShortVersionString string in your plist.info and read that programmatically using the provided API.

  • As I describe here, I use a script to rewrite a header file with my current Subversion revision number. That revision number is stored in the kRevisionNumber constant. I can then access the version and revision number using something similar to the following:

    [NSString stringWithFormat:@"Version %@ (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"], kRevisionNumber]
    

    which will create a string of the format "Version 1.0 (51)".

  • Read the info.plist file of your app and get the value for key CFBundleShortVersionString. Reading info.plist will give you an NSDictionary object

0 comments:

Post a Comment