如何以编程方式检查应用程序的捆绑版本?

MD.*_*MD. 27 iphone

我已经创建了一个应用程序,并且已经在我的iphone上安装了它,但是我想以编程方式检查我的应用程序包版本.怎么办?

Vla*_*mir 73

NSString *versionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey];
Run Code Online (Sandbox Code Playgroud)

  • 在宏的末尾没有分号.它应该被称为BUNDLE_VERSION. (4认同)

Col*_*ips 16

这是一些宏:

#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)
Run Code Online (Sandbox Code Playgroud)