zoukankan      html  css  js  c++  java
  • iOS 中系统与 SDK 版本检测

    一、编译时检测

    1. 判断 SDK 是否是某个版本或更高版本

    ifdef __IPHONE_11_0
    

    2.判断当前需要支持的最低版本

     __IPHONE_OS_VERSION_MIN_REQUIRED
    

    ​ 这个宏的取值也就是 __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ 这个值,也就是你的工程支持的最低系统版本。但是最少是 __IPHONE_2_0。

    3.判断最高可支持的系统版本

    _IPHONE_OS_VERSION_MAX_ALLOWED
    

    这个宏的值等于当前 SDK 定义的最高版本,比如 __IPHONE_11_3

    二、运行时检测

    1.iOS 11.0 SDK 引入的

    @available(iOS 11.0, *) 
    

    2.iOS 10.0 SDK 之前

    NSFoundationVersionNumber   (NSFoundationVersionNumber_iOS_9_x_Max)
    
    kCFCoreFoundationVersionNumber   (kCFCoreFoundationVersionNumber_iOS_9_x_Max)
    

    以前可以通过这两个常量来判断系统,但是10.0以后定义的数值系统并没有开放出来。

    if (NSFoundationVersionNumber > floor(NSFoundationVersionNumber_iOS_9_x_Max)) {
       // > iOS 10.0
    } else {
       // <= iOS 10.0
    }
    

    3.UIDevice 方法

    NSString *sysVersion = [UIDevice currentDevice].systemVersion
        
    if ([sysVersion compare:@"10.0.3" options:NSNumericSearch] == NSOrderedAscending) {
        // > 10.0.3
    }
    

    4.NSProcessInfo方法

    iOS 8.0 SDK 引入的方法

    if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){.majorVersion = 8, .minorVersion = 3, .patchVersion = 0}]) {
         // >= iOS 8.3
    } else {
         // < iOS 8.3
    }
    
  • 相关阅读:
    步步为营-15-文件夹的操作
    步步为营-14-文件操作
    步步为营-13-日期转化
    步步为营-12-Dictionary-翻译
    步步为营-11-List<T>泛型的简单练习
    步步为营-10-string的简单操作
    步步为营-09-简单工厂类-计算器
    B. Fixed Points
    C. Cd and pwd commands
    Queries on a String
  • 原文地址:https://www.cnblogs.com/v2m_/p/9106110.html
Copyright © 2011-2022 走看看