views:

201

answers:

3

In my app I am using the agvtool to update the build number. I would now like to have the version of my app that appears in the settings to display this number and have it update automatically.

I have seen a few apps work around this by writing a script to ready the value and populate the value then in the root.plist. I was wondering if there is a more elegant way of doing this.

+4  A: 

I don't know your agvtool but the way I get my application version from the code is :

[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];

This gets the version number from the info.plist that you have to define before uploading your app to iTunesConnect, so this should be ok : you rely on a value that you have to define anyway.

yonel
agvtool is Apple Generic Versioning Tool. You are correct about it being able to retrieve it from code, but my problem is that I would like it to appear in the settings for the app and the settings are loaded from a property list (root.plist). I could, when I run the app, populate the setting by reading it then writing it to the settings but it would not get around the problem of when someone opens the settings first
Liam
+1  A: 

You are looking for this. It includes information on how to set up and manage your marketing version and build number information. Then, when you need the build string, do something akin to the following:

NSString *marketingVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *buildNumber = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];

self.appVersionLabel.text = [NSString stringWithFormat:@"%@.%@", marketingVersion, buildNumber];
Ken Wootton
Hi Ken, Thanks for the response, but what I was looking for is a way to reference the version in the settings of my app. As I pointed out above, I could just read the version when the app starts and populate the settings then, but this would not work if the person opens the settings first. I think the only way is to have a script to copy the value across
Liam
+2  A: 

It looks like the only way is to create a script to extract the number and update the plist file. The following site give a good description of what the script needs to contain

http://davedelong.com/blog/2009/04/15/incrementing-build-numbers-xcode

Liam
+1 hmmm that link looks familiar...
Dave DeLong