2010-02-11 12 views

risposta

119

Vedere Getting the Bundle’s Info.plist Data.

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

dovrebbe ottenere la versione bundle.

+0

Perfetto, grazie! –

+0

Altre informazioni possono essere trovate in (un duplicato): [Come posso verificare la versione del pacchetto della nostra applicazione a livello di programmazione?] (Http://stackoverflow.com/questions/2657477/how-can-i-check-the -bundle-version-of-our-application-programmatic) – Guy

+3

'[[NSBundle mainBundle] objectForInfoDictionaryKey: @" CFBundleShortVersionString "];' otterrai la stringa della versione corta come mostrato nella risposta di seguito (semplicemente postando la versione objc) – smileham

14

In Swift è possibile utilizzare:

let bundleVersion: String = NSBundle.mainBundle().objectForInfoDictionaryKey(kCFBundleVersionKey as String) as! String 

o:

let bundleVersion: String = NSBundle.mainBundle().infoDictionary?[kCFBundleVersionKey as String] as! String 

Se si desidera che la stringa di versioni fascio breve, è possibile utilizzare:

let shortBundleVersion: String = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String 
-1
#define APP_VERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey] 
Problemi correlati