4

Here I'm pasting my codes where I want to retrieve Bundle version from my test-Info.plist.

@interface testViewController : UIViewController {
    UILabel *label;
}
@property(nonatomic,retain) IBOutlet    UILabel *label;

@end

@implementation testViewController

@synthesize label;

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"test-info" ofType:@"plist"];

    NSString *versionString = [NSString stringWithFormat:@"v%d", [plistData objectForKey:@"Bundle version"]];

    label.text = versionString;
}

@end

But still I got null value where I'm wrong

Cœur
  • 37,241
  • 25
  • 195
  • 267
AG007
  • 279
  • 1
  • 7
  • 18
  • You really should post only that part of code that is relevant to your question - it is hard to browse hundred lines of code to find it... – Vladimir Apr 20 '10 at 13:48
  • Also check this question: http://stackoverflow.com/questions/2657477/how-to-check-bundle-version-for-our-application-by-programming/2657500 – Vladimir Apr 20 '10 at 13:53
  • Possible duplicate of [How to read the Bundle version from PList?](http://stackoverflow.com/questions/2244985/how-to-read-the-bundle-version-from-plist) – Cœur Dec 26 '16 at 15:36

2 Answers2

36

The following line will retrieve the version for you

[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
Liam
  • 7,762
  • 4
  • 26
  • 27
  • 7
    Also worth noting: the "Bundle Version" or `CFBundleVersion` equates to the app's build number. If you want the actual "x.y" string, use `CFBundleShortVersionString` instead. – jemmons Mar 13 '13 at 02:36
1

Try getting the plist path by doing this:

NSString *path = [[NSBundle mainBundle] pathForResource:@"test-info" ofType:@"plist"];
Nick Forge
  • 21,344
  • 7
  • 55
  • 78
  • still i m getting null value in my label – AG007 Apr 20 '10 at 14:30
  • `[plistData objectForKey:@"Bundle version"]` will return an `NSNumber`. Either use `@"v%@"` in the format string to convert the NSNumber (you should always use `%@` for Obj-C objects in format strings), or keep it as `@"v%d"` and use `[[plistData objectForKey:@"Bundle version"] intValue]` to convert the `NSNumber` into an `int`. – Nick Forge Apr 23 '10 at 07:17