tags:

views:

1881

answers:

4

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?

+1  A: 

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.

RedFilter
+8  A: 

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

Jasper Bekkers
+6  A: 

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)".

Brad Larson
A: 

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

lostInTransit