<bdo id='dxcOF'></bdo><ul id='dxcOF'></ul>
  • <small id='dxcOF'></small><noframes id='dxcOF'>

      1. <tfoot id='dxcOF'></tfoot>
      2. <i id='dxcOF'><tr id='dxcOF'><dt id='dxcOF'><q id='dxcOF'><span id='dxcOF'><b id='dxcOF'><form id='dxcOF'><ins id='dxcOF'></ins><ul id='dxcOF'></ul><sub id='dxcOF'></sub></form><legend id='dxcOF'></legend><bdo id='dxcOF'><pre id='dxcOF'><center id='dxcOF'></center></pre></bdo></b><th id='dxcOF'></th></span></q></dt></tr></i><div id='dxcOF'><tfoot id='dxcOF'></tfoot><dl id='dxcOF'><fieldset id='dxcOF'></fieldset></dl></div>
        <legend id='dxcOF'><style id='dxcOF'><dir id='dxcOF'><q id='dxcOF'></q></dir></style></legend>

      3. 我们如何以编程方式检测设备在哪个 iOS 版本上运行?

        时间:2023-10-03
        <i id='qA8Pl'><tr id='qA8Pl'><dt id='qA8Pl'><q id='qA8Pl'><span id='qA8Pl'><b id='qA8Pl'><form id='qA8Pl'><ins id='qA8Pl'></ins><ul id='qA8Pl'></ul><sub id='qA8Pl'></sub></form><legend id='qA8Pl'></legend><bdo id='qA8Pl'><pre id='qA8Pl'><center id='qA8Pl'></center></pre></bdo></b><th id='qA8Pl'></th></span></q></dt></tr></i><div id='qA8Pl'><tfoot id='qA8Pl'></tfoot><dl id='qA8Pl'><fieldset id='qA8Pl'></fieldset></dl></div>

        • <bdo id='qA8Pl'></bdo><ul id='qA8Pl'></ul>

          <legend id='qA8Pl'><style id='qA8Pl'><dir id='qA8Pl'><q id='qA8Pl'></q></dir></style></legend>

          <small id='qA8Pl'></small><noframes id='qA8Pl'>

              <tbody id='qA8Pl'></tbody>
            <tfoot id='qA8Pl'></tfoot>

                  本文介绍了我们如何以编程方式检测设备在哪个 iOS 版本上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想检查用户是否在低于 5.0 的 iOS 上运行应用并在应用中显示标签.

                  I want to check if the user is running the app on iOS less than 5.0 and display a label in the app.

                  如何以编程方式检测用户设备上运行的是哪个 iOS?

                  How do I detect which iOS is running on user's device programmatically?

                  谢谢!

                  推荐答案

                  目前最好的版本,不需要处理NSString内的数字搜索就是定义macros(见原答案:检查 iPhone iOS 版本)

                  Best current version, without need to deal with numeric search within NSString is to define macros (See original answer: Check iPhone iOS Version)

                  这些宏确实存在于 github 中,请参阅:https://github.com/carlj/CJAMacros/blob/master/CJAMacros/CJAMacros.h

                  Those macros do exist in github, see: https://github.com/carlj/CJAMacros/blob/master/CJAMacros/CJAMacros.h

                  像这样:

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

                  并像这样使用它们:

                  if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
                      // code here
                  }
                  
                  if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {
                      // code here
                  }
                  

                  <小时>

                  以下是过时版本

                  获取操作系统版本:


                  Outdated version below

                  to get OS version:

                  [[UIDevice currentDevice] systemVersion]
                  

                  返回字符串,可以通过转成int/float

                  returns string, which can be turned into int/float via

                  -[NSString floatValue]
                  -[NSString intValue]
                  

                  喜欢这个

                  两个值 (floatValue, intValue) 将因其类型而被剥离,5.0.1 将变为 5.0 或 5 (float 或 int),为了精确比较,您必须将其分隔为 INT 数组在此处检查接受的答案:检查 iPhone iOS 版本

                  Both values (floatValue, intValue) will be stripped due to its type, 5.0.1 will become 5.0 or 5 (float or int), for comparing precisely, you will have to separate it to array of INTs check accepted answer here: Check iPhone iOS Version

                  NSString *ver = [[UIDevice currentDevice] systemVersion];
                  int ver_int = [ver intValue];
                  float ver_float = [ver floatValue];
                  

                  然后像这样比较

                  NSLog(@"System Version is %@",[[UIDevice currentDevice] systemVersion]);
                  NSString *ver = [[UIDevice currentDevice] systemVersion];
                  float ver_float = [ver floatValue];
                  if (ver_float < 5.0) return false;
                  

                  适用于 Swift 4.0 语法

                  以下示例只是检查设备是否为 iOS11 或更高版本.

                  below example is just checking if the device is of iOS11 or greater version.

                  let systemVersion = UIDevice.current.systemVersion
                  if systemVersion.cgFloatValue >= 11.0 {
                      //"for ios 11"
                    }
                  else{
                     //"ios below 11")
                    }
                  

                  这篇关于我们如何以编程方式检测设备在哪个 iOS 版本上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将水平 recylerview 的滚动与 viewpager 滚动同步 下一篇:安装带有 iPhone SDK 4 的 Xcode 3.2.3,得到“缺少基本 SDK",看不到其他 SDK

                  相关文章

                  <small id='EyRmR'></small><noframes id='EyRmR'>

                1. <i id='EyRmR'><tr id='EyRmR'><dt id='EyRmR'><q id='EyRmR'><span id='EyRmR'><b id='EyRmR'><form id='EyRmR'><ins id='EyRmR'></ins><ul id='EyRmR'></ul><sub id='EyRmR'></sub></form><legend id='EyRmR'></legend><bdo id='EyRmR'><pre id='EyRmR'><center id='EyRmR'></center></pre></bdo></b><th id='EyRmR'></th></span></q></dt></tr></i><div id='EyRmR'><tfoot id='EyRmR'></tfoot><dl id='EyRmR'><fieldset id='EyRmR'></fieldset></dl></div>
                    <bdo id='EyRmR'></bdo><ul id='EyRmR'></ul>
                  <tfoot id='EyRmR'></tfoot>
                2. <legend id='EyRmR'><style id='EyRmR'><dir id='EyRmR'><q id='EyRmR'></q></dir></style></legend>