美文网首页征服iOS
IOS不同版本的判断

IOS不同版本的判断

作者: 代码干货 | 来源:发表于2015-06-30 23:46 被阅读1815次

    系统版本的判断
    <pre><code>
    /*

    • 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")) {
    ...
    }

    或者

    define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)

    define IS_OS_5_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0)

    define IS_OS_6_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)

    define IS_OS_7_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)

    define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

    </code></pre>

    APP版本的判断
    <pre><code>

    • (NSString *) appVersion
      {
      return [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
      }
      </code></pre>

    build版本判断
    <pre><code>

    • (NSString *) build
      {
      return [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString *)kCFBundleVersionKey];
      }
      </code></pre>

    参考链接:
    How to check iOS version?

    Best Way to check for iOS 7 or earlier?

    相关文章

      网友评论

        本文标题:IOS不同版本的判断

        本文链接:https://www.haomeiwen.com/subject/ywaeqttx.html