26

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?

0

2 Answers 2

72
NSString *versionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey];
3
  • How would one make a macro out of this?
    – Rits
    Dec 4, 2010 at 23:51
  • 1
    #define APP_VERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey];
    – powerj1984
    Jul 18, 2013 at 14:33
  • 4
    no semicolon at the end of the macro. and it should probably be called BUNDLE_VERSION.
    – Moe Salih
    Aug 17, 2013 at 4: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)

Not the answer you're looking for? Browse other questions tagged or ask your own question.