【问题标题】:Detects iOS 7.1 version检测 iOS 7.1 版本
【发布时间】:2014-03-13 09:34:57
【问题描述】:

我用这个代码

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

【问题讨论】:

  • 看起来 7.1 是 1047.25

标签: ios ios7 ios7.1


【解决方案1】:

有几种方法可以做到这一点,您可以在 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?

【讨论】:

  • 这很好,但它比 NSFoundationVerstionNumber 运行得慢。
  • @Dzmitry 什么慢?我提出了 3 种方法,其中 NSFoundationVersionNumber 是第二个...
  • 3 号版本的运行速度比 2 号版本慢。我检查了它。
  • 是的,可能。但如果你需要,它会更细粒度。对于大多数情况,版本 2 可能是最好的。不过,感谢您分享您的结果。
【解决方案2】:

试试下面的代码

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

【讨论】:

    【解决方案3】:

    定义这个宏

    #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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-17
      • 1970-01-01
      • 2015-09-05
      • 2011-12-07
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多