ios - 如何查看iOS版本?

我要检查设备的iOS版本是否大于3.1.3 我试过这样的事情:

[[UIDevice currentDevice].systemVersion floatValue]

但它不起作用,我只想要一个:

if (version > 3.1.3) { }

我怎样才能做到这一点?

最佳答案

/*
 *  System Versioning Preprocessor Macros
 */ 

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

/*
 *  Usage
 */ 

if (SYSTEM_VERSION_LESS_THAN(@"4.0")) {
    ...
}

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"3.1.1")) {
    ...
}

https://stackoverflow.com/questions/3339722/

相关文章:

objective-c - 在 Objective-C 中生成随机数

ios - 如何在 Objective-C 中测试字符串是否为空?

ios - UITextView 中的占位符

objective-c - @class 与 #import

ios - 如何链接到应用商店中的应用

ios - 在 Objective-C 中通过 NSNotificationCenter 发送和接收

ios - 延迟后如何触发 block ,例如 -performSelector :withObje

ios - 如何在 Objective-C 中创建委托(delegate)?

objective-c - 定位服务在 iOS 8 中不起作用

objective-c - 如何将 NSString 转换为 NSNumber