好吧,能找到这文章的,一般是接到了如下需求: 

我是从raywenderlich抽了点内容出来做日记,另外,本文说的不是布局的适配,而是因为ios的升级带来的各版本代码上的不兼容。

Deployment Target vs. Base SDK

总的来说,Base SDK表示你愿意支持的最高版本,位于你要设置的Target的属性页的Build Settings > Architectures,一般就选择Latest iOS即可,比如我写这篇日志的时候已经是8.0了 
而Deployment Target则表示了你愿意支持的最低版本,位于同样的Build Setting下的Deployment一节里面,你可以找到iOS Deployment Target

发现兼容问题

这个简单:

运行老旧系统的真机

你有那么多机器的话

运行模拟器

你有装那么多SDK的话,当然这个也不是不可能啦

苹果的文档

Header Files

原文如下,但是我真没发现Command-click后跳转的有 NS_AVAILABLE_IOS() and NS_CLASS_AVAILABLE_IOS()这两个宏,这不能说明就没有兼容性问题吧?。。。
Sometimes the best documentation of methods and classes is contained right in the source code.
Simply Command-click the symbol you want to inspect, and Xcode will take you to its header file, where you will find the information you need along with the parameters of the preprocessor macros NS_AVAILABLE_IOS() and NS_CLASS_AVAILABLE_IOS(). If a class or method declaration doesn’t use either of those availability macros, you can assume that they won’t cause any compatibility issues.

Note: ALT + click on a method will display a popover that contains these same details along with other information about the method.

苹果提供的Apid Diffs

这个应该是最全的了
https://developer.apple.com/library/ios/releasenotes/General/iOS60APIDiffs/
https://developer.apple.com/library/ios/releasenotes/General/iOS70APIDiffs/
依次类推,
当然预览状态的就是如下了:
https://developer.apple.com/library/prerelease/ios/releasenotes/General/iOS80APIDiffs/

Deploymate

这是一个付费服务,简单来说,花钱外包了。油条帮上的演示视频deploymate,自行翻墙

MJGAvailability

一个示例头文件,来自MJGFoundation,会欺骗编译器某些api已经deprecated了,从而触发警告,用法在文件头已经说得很清楚了,自己可以试试。

解决兼容问题

新版本会引入新的框架、类、方法、常量以及枚举,分别如下

frameworks

Build Phases -> Link Binary With Libraries,将特定框架从Required改为Optional,这将会weak link你选定的框架

classes

目标版本可能不支持的类,文章提供的是iOS4.2的写法,严重怀疑现在有了新的写法,或者已经不支持了,希望有人留个言:

if ([SLComposeViewController class]) {
//Safe to use SLComposeViewController
} else {
//Fail gracefully
}

methods

if ([self.image respondsToSelector:@selector(resizableImageWithCapInsets:resizingMode:)]) {
//Safe to use this way of creating resizable images
} else {
//Fail gracefully
}

如果是类方法,用类而不是实例即可:

if ([UIView respondsToSelector:@selector(requiresConstraintBasedLayout)]) {
//Safe to use this method
} else {
//Fail gracefully
}

同样的方法可以探测类是否支持某个属性,比如UILabel是否有attributedText,可以用@selector(setAttributedText)

constants/C functions

一般表现为extern NSString *或C语言的方法,比如一个iOS6引入的c方法ABAddressBookCreateWithOptions(...),在iOS5中想不挂掉可以这么判断:

if (ABAddressBookCreateWithOptions != NULL) {
//Safe to use
}
else {
//Fail gracefully
}

常量也一样:

if (&UIApplicationWillEnterForegroundNotification) {
//Safe to assume multitasking support
}
else {
//Fail gracefully
}

enumeration values

请看原文
Checking for the existence of enumeration or bit mask values — the kind that you would find inside an NS_ENUM or NS_OPTIONS declaration — is incredibly difficult to check at runtime. Why?
Under the hood, an enumeration is just a method of giving names to numeric constants. An enum is replaced with an int when compiled, which always exists!
If you’re faced with the situation of needing to see if a certain enumeration exists, all you can do is either explicitly check the OS version (which isn’t recommended) or alternatively check against another API element that was introduced at the same time as the new enumeration value.

Note: Whichever way you do this, be sure to add adequate comments to any such code and consider wrapping the code in a dedicated compatibility helper.

显式版本检测

NSString *osVersion = [[UIDevice currentDevice] systemVersion];, 但作者不推荐。。。

最后,水果官方的兼容性指南:SDK Compatibility Guide

iOS多版本多设备适配的问题的更多相关文章

  1. iOS系统版本简介

    iOS系统版本简介 ⽬目前iOS设备所⽀支持的最主流操作系统是iOS6,⼤大概占了93%,⽽而使 ⽤用iOS5的iOS设备⼤大概占6%,剩下的只有1%.( 根据苹果的官⽅方数据 ) 从iOS1到现在的 ...

  2. WebSocket学习笔记IE,IOS,Android等设备的兼容性问

    WebSocket学习笔记IE,IOS,Android等设备的兼容性问 一.背景 公司最近准备将一套产品放到Andriod和IOS上面去,为了统一应用的开发方式,决定用各平台APP嵌套一个HTML5浏 ...

  3. iOS开发小技巧 - runtime适配字体

    iOS开发小技巧 - runtime适配字体 版权声明:本文为博主原创文章,未经博主允许不得转载,有问题可联系博主Email: liuyongjiesail@icloud.com 一个iOS开发项目无 ...

  4. 【代码笔记】iOS-手机版本号,机型,操作系统版本,设备唯一标识符

    一,代码. RootViewController.m #import "ViewController.h" #import "sys/utsname.h" @i ...

  5. 038改变状态栏的颜色(扩展知识:关于iOS不同版本的消息通知知识)

    效果如下: ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController @e ...

  6. 【ARM-Linux开发】内核3.x版本之后设备树机制

    内核3.x版本之后设备树机制 Based  on  Linux  3.10.24  source  code  参考/documentation/devicetree/Booting-without- ...

  7. iOS各别版本new Date().getTime 获取时间戳为null问题

    正常逻辑 new Date('2019-9-8').getTime() 注意日期格式 yyyy--mm-dd 因为yyyy/mm/dd也有兼容性问题 但是各别iOS版本不支持 // IOS 获取时间戳 ...

  8. js中如果遇到低版本安卓设备调用setTimeout不生效解决办法

    工作中会遇到低版本安卓设备调用setTimeout不生效,既不会报错,里面的函数也不会执行,这里po一个解决办法,如果不执行则执行安卓自己封装的原生的setTimeout方法:sdk.setTimeo ...

  9. fetch ios低版本兼容cannot clone a disturbed response

    报错信息 ios 11以下 cannot clone a disturbed response github.com/github/fetc- 问题发生场景 使用了一个或者多个三方库 三方库或者自己的 ...

随机推荐

  1. Linux下如何查看tomcat是否启动,并杀死重启

    在Linux系统下,遇到过这样的问题,项目中使用 ./shutdown.sh 关闭Tomcat失败 Using CATALINA_BASE: /usr/local/tomcat Using CATAL ...

  2. 联通GWH-01路由猫超级用户登录方法

    . . . . . 今天回老家,家里用的是联通GWH-01路由猫,上海贝尔的.用路由器背面说明上面写的user用户登录之后,发现只能查看却无法设置.为了开启无线路由功能,只好在网上查找超级用户,是cu ...

  3. 在SQL Server中创建用户角色及授权

    参考文献 http://database.51cto.com/art/201009/224075.htm 正文 要想成功访问 SQL Server 数据库中的数据, 我们需要两个方面的授权: 获得准许 ...

  4. [Linux]Shell的运算符和特殊变量

    说起Shell脚本,免不了用变量.特别是对于这种一堆符号表示变量的语言来说,你不了解一下相关变量的本意,根本无从下手.譬如写个循环遍历,$#就起了好大作用.所以还是有必要记录一下,也是对学习的一个笔记 ...

  5. git——从远程库克隆

    从远程库克隆 阅读: 248434 上次我们讲了先有本地库,后有远程库的时候,如何关联远程库. 现在,假设我们从零开发,那么最好的方式是先创建远程库,然后,从远程库克隆. 首先,登陆GitHub,创建 ...

  6. WIN7下重建图标缓存(解决MFC.exe桌面图标显示异常问题)

    WIN7下重建图标缓存 使用WIN7时,MFC工程生成的应用程序图标,如果更改为自定义的ICON图标之后可能在桌面上显示的依旧是上一次的图标,改个名或换个路径都能恢复正常,说明在WIN7系统下图标的缓 ...

  7. 【C】——C语言字符串比较函数

    c语言字符串函数详解 void *memset(void *dest, int c, size_t count); 将dest前面count个字符置为字符c. 返回dest的值. void *memm ...

  8. HTML select 选中触发事件

    $(function () { $("#cityidchange").change(function (data) { var cityid = $("#cityidch ...

  9. 快速排序算法(Quicksort)

    快速排序算法是对集合中元素进行排序最通用的算法,俗称快排,其算法的时间复杂度为O(nlgn),空间复杂度为O(1). 我们举例来对其算法思路进行理解,譬如数组 A = { 4, 8, 1, 2, 9, ...

  10. js文档碎片

    //文档碎片:类似一个临时的文档,要所有要加的dom元素先放在这里,达到不要每次操作dom元素提高页面效率 var d1 = new Date(); //创建十个段落,常规的方式 ; i < ; ...