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 的数字进行比较,但我不知道。有人得到安全可靠的解决方案吗?

4

3 回答 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 版本上运行?

于 2014-03-13T13:51:52.727 回答
2

试试下面的代码

 float fOSVersion=[[[UIDevice currentDevice] systemVersion] floatValue];
     if(fOSVersion>7.0)//if it is greater than 7.0
     {
          //do your stuff here          
     }
于 2014-03-13T13:00:56.100 回答
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
}
于 2014-03-13T09:40:25.963 回答