检测iOS 7.1版本

我用这个代码
#define IS_IOS7 (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1)

查找应用程序是否在iOS7上运行.
但我现在需要知道它是否在iOS7.1上运行,但是没有任何NSFoundationVersionNumber_iOS_7_0和NSFoundationVersionNumber_iOS_7_1

我知道的定义

#define NSFoundationVersionNumber_iOS_6_1  993.00

所以也许我可以比较高于993的数字,但我不知道.
有人得到安全可靠的解决方案吗?

解决方法

有几种方法可以做到这一点,你可以在SO上的几个答案中轻松找到它们.这里有一些:
[[UIDevice currentDevice] systemVersion]

稍微复杂一点,测试:

if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
    // iOS7...
}

您可以添加更完整的方法来测试这样的版本:

/*
 *  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")) {
    ...
}

资料来源:

How to check iOS version?

How can we programmatically detect which iOS version is device running on?

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...