检测iOS 7.1版本

7
我使用这段代码。
#define IS_IOS7 (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1)

如何判断应用程序是否在iOS7上运行。

但现在我需要知道它是否在iOS7.1上运行,但是没有NSFoundationVersionNumber_iOS_7_0NSFoundationVersionNumber_iOS_7_1

我知道这个定义。

#define NSFoundationVersionNumber_iOS_6_1  993.00

也许我可以与大于993的数字进行比较,但我不确定。 有人能提供一个安全可靠的解决方案吗?

3
看起来7.1是1047.25。 - Mike Pollard
3个回答

9

有几种方法可以做到这一点,你可以很容易地在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")) {
    ...
}

参考资料:

如何检查iOS版本?

我们如何编程检测设备运行的iOS版本?


它还不错,但是它的运行速度比NSFoundationVerstionNumber慢。 - Dzmitry
@Dzmitry 什么更慢?我提出了3种方法,其中NSFoundationVersionNumber是第二个... - Marius Waldal
第三个版本比第二个版本运行速度慢。我进行了检查。 - Dzmitry
是的,可能吧。但如果你需要更细致的控制,版本2可能是大多数情况下最好的选择。不过还是感谢你分享你的结果。 - Marius Waldal

2

尝试下面的代码:

 float fOSVersion=[[[UIDevice currentDevice] systemVersion] floatValue];
     if(fOSVersion>7.0)//if it is greater than 7.0
     {
          //do your stuff here          
     }

1

定义此宏

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

你可以像这样检查版本
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.1")){
   //do something
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接