IOS开发之不同版本适配问题2(#ifdef __IPHONE_7_0)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了IOS开发之不同版本适配问题2(#ifdef __IPHONE_7_0),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2588字,纯文字阅读大概需要4分钟。
内容图文
继续说说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
所以……就不多解释了……
原文:http://blog.csdn.net/zwf_apple/article/details/21649397
内容总结
以上是互联网集市为您收集整理的IOS开发之不同版本适配问题2(#ifdef __IPHONE_7_0)全部内容,希望文章能够帮你解决IOS开发之不同版本适配问题2(#ifdef __IPHONE_7_0)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。