49

Is there a way to read the app's bundled plist file, I am wanting to pull the value for Bundle version.

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
Rob Bonner
  • 9,276
  • 8
  • 35
  • 55

3 Answers3

123

See Getting the Bundle’s Info.plist Data.

[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];

should get you the bundle version.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • Some more information can be found in (a duplicate): [How can I check the bundle version of our application programmatically?](http://stackoverflow.com/questions/2657477/how-can-i-check-the-bundle-version-of-our-application-programmatically) – Guy Oct 28 '14 at 10:28
  • 3
    `[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];` will get you the short version string as shown in the answer below (just posting the objc version) – smileham Apr 12 '16 at 15:55
  • hi OleB, the document link is outdated – Quang Vĩnh Hà May 28 '19 at 06:27
16

In Swift you can use:

let bundleVersion = Bundle.main.object(forInfoDictionaryKeykCFBundleVersionKey as String) as! String

or:

let bundleVersion = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as! String

If you want the short bundle versions string, you can use:

let shortBundleVersion = Bundle.main.object(forInfoDictionaryKey:"CFBundleShortVersionString") as! String
Paulw11
  • 108,386
  • 14
  • 159
  • 186
PassKit
  • 12,231
  • 5
  • 57
  • 75
-1
#define APP_VERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey] 
Fabio Poloni
  • 8,219
  • 5
  • 44
  • 74
Hardik Darji
  • 3,633
  • 1
  • 30
  • 30