检测iOS 7.1版本

前端之家收集整理的这篇文章主要介绍了检测iOS 7.1版本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我用这个代码
  1. #define IS_IOS7 (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1)

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

我知道的定义

  1. #define NSFoundationVersionNumber_iOS_6_1 993.00

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

解决方法

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

稍微复杂一点,测试:

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

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

  1. /*
  2. * System Versioning Preprocessor Macros
  3. */
  4.  
  5. #define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
  6. #define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
  7. #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
  8. #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
  9. #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
  10.  
  11. /*
  12. * Usage
  13. */
  14.  
  15. if (SYSTEM_VERSION_LESS_THAN(@"4.0")) {
  16. ...
  17. }
  18.  
  19. if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"3.1.1")) {
  20. ...
  21. }

资料来源:

How to check iOS version?

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

猜你在找的iOS相关文章