iOS后向兼容:如何发现过期接口

以4.3以下兼容性为例,在项目预编译头文件(xx.pch)中加入如下代码:

#import <Availability.h>
#define __AVAILABILITY_INTERNAL__IPHONE_3_2 __AVAILABILITY_INTERNAL_DEPRECATED
#define __AVAILABILITY_INTERNAL__IPHONE_4_0 __AVAILABILITY_INTERNAL_DEPRECATED
#define __AVAILABILITY_INTERNAL__IPHONE_4_1 __AVAILABILITY_INTERNAL_DEPRECATED
#define __AVAILABILITY_INTERNAL__IPHONE_4_2 __AVAILABILITY_INTERNAL_DEPRECATED
#define __AVAILABILITY_INTERNAL__IPHONE_4_3 __AVAILABILITY_INTERNAL_DEPRECATED

然后,编译程序,在warning中会列出不再支持的方法,逐个检查,在可能引起程序crash的地方,加入 if ( [xx respondToSelector:(deprecatedMethod)] ) { ... } 判断。

也可以加入如下代码将warning变成error:

#import <Availability.h>
#define __AVAILABILITY_INTERNAL__IPHONE_3_2 __AVAILABILITY_INTERNAL_UNAVAILABLE
#define __AVAILABILITY_INTERNAL__IPHONE_4_0 __AVAILABILITY_INTERNAL_UNAVAILABLE
#define __AVAILABILITY_INTERNAL__IPHONE_4_1 __AVAILABILITY_INTERNAL_UNAVAILABLE
#define __AVAILABILITY_INTERNAL__IPHONE_4_2 __AVAILABILITY_INTERNAL_UNAVAILABLE
#define __AVAILABILITY_INTERNAL__IPHONE_4_3 __AVAILABILITY_INTERNAL_UNAVAILABLE

不兼容的方法会以编译错误列出。

参考:http://*.com/questions/7790497/iphone-app-developed-with-sdk-4-2-requires-backward-compatibility-with-ios-3-1

另外这个不错:

iOS Support Matrix

http://iossupportmatrix.com/versions/summer-2013-version-2-4-1

上一篇:unity碰撞组件、刚体组件


下一篇:详解CSS float属性(转)