I have made an application and I have installed it on my iphone, but I want to check my application bundle version programatically. How can that be done?
Asked
Active
Viewed 1.3k times
2 Answers
72
NSString *versionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey];

Vladimir
- 170,431
- 36
- 387
- 313
-
How would one make a macro out of this? – Rits Dec 04 '10 at 23:51
-
1#define APP_VERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey]; – powerj1984 Jul 18 '13 at 14:33
-
4no semicolon at the end of the macro. and it should probably be called BUNDLE_VERSION. – Moe Salih Aug 17 '13 at 04:55
16
Here are some macros:
#define BUNDLE_VERSION_EQUAL_TO(v) ([[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*) kCFBundleVersionKey] compare:v options:NSNumericSearch] == NSOrderedSame)
#define BUNDLE_VERSION_GREATER_THAN(v) ([[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*) kCFBundleVersionKey] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define BUNDLE_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*) kCFBundleVersionKey] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define BUNDLE_VERSION_LESS_THAN(v) ([[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*) kCFBundleVersionKey] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define BUNDLE_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*) kCFBundleVersionKey] compare:v options:NSNumericSearch] != NSOrderedDescending)

Colin Phillips
- 1,001
- 1
- 10
- 11