zoukankan      html  css  js  c++  java
  • 适配版本

    下面举个简单的例子来说明在iOS7.0和iOS6.1(以及更低版本)之间的适配问题(用的是xcode5.0,里边有6.1和7.0两个版本的sdk)

    新建一个工程,默认的development target,base sdk以及模拟器的版本都是7.0,在AppDelegate中的didFinishLaunchingWithOptions方法里

      self.window.tintColor = [UIColor redColor];  


    然后运行,这样是没有任何错误的。接下来将development target,base sdk以及模拟器的版本都改成6.1(注意默认的xcode是没有6.1的sdk的,需要自己另外导入)。然后运行,就会报错:


    也就是说tintColor属性在iOS6.1中根本就没有,在编译时候就会出错。这时候如下加上判断语句也是没有用的,照样报错

      if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {  

        self.window.tintColor = [UIColor redColor];  

      }  


    遇见这种情况只能加上预处理语句,这样写:

      #ifdef __IPHONE_7_0  

        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {  

            self.window.tintColor = [UIColor redColor];  

        }  

      #endif  


    这样编译通过就不会报错了……这是因为在sdk6.1下的usr/include下边有一个Availability.h文件,里边定义了一大堆宏,其中关于iphone的有

    #define __IPHONE_2_0     20000  

    #define __IPHONE_2_1     20100  

    #define __IPHONE_2_2     20200  

    #define __IPHONE_3_0     30000  

    #define __IPHONE_3_1     30100  

    #define __IPHONE_3_2     30200  

    #define __IPHONE_4_0     40000  

    #define __IPHONE_4_1     40100  

    #define __IPHONE_4_2     40200  

    #define __IPHONE_4_3     40300  

    #define __IPHONE_5_0     50000  

    #define __IPHONE_5_1     50100  

    #define __IPHONE_6_0     60000  

    #define __IPHONE_6_1     60100  

    #define __IPHONE_NA      99999  /* not available */  


      在sdk7.0里多了一个

      #define __IPHONE_7_0     70000  

  • 相关阅读:
    Oracle 连接字符串
    C# Entity Framework Core 各个数据库连接Context
    jquery的几个语法总结和注意事项
    Jquery的load()
    针对PHP性能方面编程技巧的总结
    编码,charset,乱码,unicode,utf-8与net简单释义
    Web测试方法
    MySQL部署时Table 'mysql.plugin' doesn't exist的解决
    IE Firefox css 差别
    Mysql日期和时间函数
  • 原文地址:https://www.cnblogs.com/mohe/p/3627842.html
Copyright © 2011-2022 走看看