AG007
AG007

Reputation: 279

How to retrieve Bundle Version in a label from project test-Info.plist in iphone?

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

Upvotes: 4

Views: 4297

Answers (2)

Liam
Liam

Reputation: 8092

The following line will retrieve the version for you

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

Upvotes: 36

Nick Forge
Nick Forge

Reputation: 21464

Try getting the plist path by doing this:

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

Upvotes: 1

Related Questions