IOS开发之不同版本适配问题2(#ifdef __IPHONE_7_0)
继续说说ios不同版本之间的适配
先说一个东西:在xcode当中有一个东西叫targets,苹果的官方文档是这样说的:
A target specifies a product to build and contains the instructions for building the product from a set of files in a project or workspace. A target defines a single product; it organizes the inputs into the build system—the source files and instructions for processing those source files—required to build that product. Projects can contain one or more targets, each of which produces one product.(省略若干字)
简单翻译过来就是一个target详细说明了要构建的产品,包含了一个工程或工作目录中的文件当中的指令,貌似还是不太清楚。在谷歌搜了一下,发现这个关于target的解释还是不错的:
A target basically defines what it is you are building and how you are building it. You can add more targets if you would like to build more than one thing. This usually makes sense if you need to build several related things from the same project. For instance, you might want one target for a full, paid version of an application, and another target for a reduced, free version of an application. Both targets would include much of the same code and resources, but some of the settings would be different and you might have different files included with each.
意思就是如果你想将一个应用分为付费完整版和免费简化版,这两个版本大部分代码是一样的,只有个别的设置和包含的文件不同,你就可以建一个application然后弄两个targets分别对应两个版本。
下面举个简单的例子来说明在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 60100
所以……就不多解释了……
IOS开发之不同版本适配问题2(#ifdef __IPHONE_7_0)的更多相关文章
- IOS开发之不同版本适配问题2(#ifdef __IPHONE_7_0)(转载)
继续说说ios不同版本之间的适配 先说一个东西:在xcode当中有一个东西叫targets,苹果的官方文档是这样说的: A target specifies a product to build an ...
- iOS开发小技巧 - runtime适配字体
iOS开发小技巧 - runtime适配字体 版权声明:本文为博主原创文章,未经博主允许不得转载,有问题可联系博主Email: liuyongjiesail@icloud.com 一个iOS开发项目无 ...
- iOS开发——UI基础-屏幕适配
一.适配 1.什么是适配?适应.兼容各种不同的情况 2.移动开发中,适配的常见种类 2.1系统适配 针对不同版本的操作系统进行适配 2.2屏幕适配 针对不同大小的屏幕尺寸进行适配 二.点和像素 1.在 ...
- iOS开发中检测版本,有新版本则更新
iOS程序自动提示更新的实现方案大致分为两种: 第一种,自己服务器提供一个接口,告知相关app的当前版本,是否需要更新,以及更新的地址等信息 . 第二种,就是利用苹果的appstore 提供的相关ap ...
- ios开发中各种版本、设备的区分
设备类型的区分-iphone ,ipad-itouch..... 可以从 UIDevice 的属性 model 得到在现在执行的环境.例子如下: [cpp] view plaincopyprint? ...
- ios开发之--使用xib适配iPhone X
最近在修改一个老项目,里面有很多xib文件,需要适配iPhone X,但是又不想重写页面用代码适配,分享个小方法,也算是个笨办法吧, 适配iPhone X底部,iPhone X底部有34px的操作区域 ...
- iOS开发之--iPhone X 适配:MJRefresh上拉加载适配
问题如下图: 出现原因,phoneX系列手机下方多了34像素的工作区域,所以需要对x全系列手机坐下适配, 解决如下: self.tableView.mj_footer.ignoredScrollVie ...
- iOS开发 适配iOS10
2016年9月7日,苹果发布iOS 10.2016年9月14日,全新的操作系统iOS 10将正式上线. 作为开发者,如何适配iOS10呢? 1.Notification(通知) 自从Notificat ...
- iOS开发——屏幕适配篇&autoResizing autoLayout和sizeClass
autoResizing autoLayout和sizeClass,VFL,Masonry详解 1. autoResizing autoresizing是苹果早期的ui布局适配的解决办法,iOS6之前 ...
随机推荐
- c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2 .
// c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2 分类: c# 2013-02-06 15:18 3008人阅读 评论(0) 收藏 举报 可以实现 ...
- DOM、JDOM、DOM4J的区别(转载)
DOM.JDOM.DOM4J的区别 分类: XML2012-06-11 20:47 5576人阅读 评论(6) 收藏 举报 文档xmlcollectionsjavaapi工作 dom是解析xml的底层 ...
- Find Minimum in Rotated Sorted Array II leetcode
题目链接 这个博客的算法思想简单好! 还是贴上自己的蹩脚代码吧!! class Solution { public: int findMin(vector<int>& nums) ...
- 多重背包问题:悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(HDU 2191)(二进制优化)
悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 HDU 2191 一道裸的多重背包问题: #include<iostream> #include<algorithm> #i ...
- oprofile 安装使用
ubuntu上要编译安装oprofile.现在版本(0.9.9)的oprofile的编译需要binutil-dev libpopt-dev apt-get install binutil-dev li ...
- SQL语句 in和inner join各有什么优点
比如A1表 100W行 A2表50W行select a.* from A1 a where a.column1 in (select b.column1 from A2 b where b.colum ...
- 用SQLSERVER里的bcp命令或者bulkinsert命令也可以把dat文件导入数据表
用SQLSERVER里的bcp命令或者bulkinsert命令也可以把dat文件导入数据表 下面的内容的实验环境我是在SQLSERVER2005上面做的 之前在园子里看到两篇文章<C# 读取纯真 ...
- qooxdoo 3.0 发布,JavaScript 的 GUI 框架
qooxdoo 3.0 是一个主要的版本,包含很多新特性和内部的改动,qooxdoo 3.0 是一个通用的 JS 框架,主要改进体现在 qx.Desktop, qx.Mobile, 和 qx.Webs ...
- [转]DOS特殊字符转义方法
http://www.robvanderwoude.com/escapechars.php 期望得到的字符 转义后字符 说明 % %% May not always be required in do ...
- node-webkit教程(7)Platform Service之APP
node-webkit教程(7)Platform Service之APP 文/玄魂 前言 几个月前,要开发一个简易的展示应用,要求支持离线播放(桌面应用)和在线播放(web应用). 当时第一想到的是f ...