2010-02-11 3 views

Répondre

119

Voir Getting the Bundle’s Info.plist Data.

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

devrait vous procurer la version de l'ensemble.

+0

Parfait, Je vous remercie! –

+0

Plus d'informations peuvent être trouvées dans (une copie): [Comment puis-je vérifier la version de l'ensemble de notre application par programme?] (Http://stackoverflow.com/questions/2657477/how-can-i-check-the -bundle-version-de-notre-application-programmatique) – Guy

+3

'[[NSBundle mainBundle] objectForInfoDictionaryKey: @" CFBundleShortVersionString "];' vous obtiendrez la chaîne de version courte comme indiqué dans la réponse ci-dessous (juste poster la version d'objc) – smileham

14

Swift vous pouvez utiliser:

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

ou:

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

Si vous voulez que la chaîne de versions courte bundle, vous pouvez utiliser:

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