IOS各版本兼容性 代码思路
2015-10-15 16:00
369 查看
有时候,我们会碰到下面的情况:
1、一些功能可能需要某一个版本之上才能使用;
2、视线某些功能的方法在不同的版本上实现方式不同;
这时候我们可以使用下面的方法。
苹果的API中提供了各版本宏定义
#define __MAC_10_0
1000
#define __MAC_10_1
1010
#define __MAC_10_2
1020
#define __MAC_10_3
1030
#define __MAC_10_4
1040
#define __MAC_10_5
1050
#define __MAC_10_6
1060
#define __MAC_10_7
1070
#define __MAC_10_8
1080
#define __MAC_10_9
1090
#define __MAC_10_10
101000
/* __MAC_NA is not defined to a value but is uses as a token by macros to indicate that the API is unavailable */
#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_7_0 70000
#define __IPHONE_7_1 70100
#define __IPHONE_8_0 80000
#define __IPHONE_8_1 80100
#define __IPHONE_8_2 80200
#define __IPHONE_8_3 80300
#define __IPHONE_8_4 80400
/* __IPHONE_NA is not defined to a value but is uses as a token by macros to indicate that the API is unavailable */
我们可以使用这些宏定义
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
// 只能在ios 下
#if __IPHONE_OS_VERSION_MIN_REQUIRED > 40300
//做一些事情
#else
//做一些事情
#endif
#endif
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
// 只能在mac os x
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050
// code in here might run on pre-Leopard OS
#else
// code here can assume Leopard or later
#endif
#endif
1、一些功能可能需要某一个版本之上才能使用;
2、视线某些功能的方法在不同的版本上实现方式不同;
这时候我们可以使用下面的方法。
苹果的API中提供了各版本宏定义
#define __MAC_10_0
1000
#define __MAC_10_1
1010
#define __MAC_10_2
1020
#define __MAC_10_3
1030
#define __MAC_10_4
1040
#define __MAC_10_5
1050
#define __MAC_10_6
1060
#define __MAC_10_7
1070
#define __MAC_10_8
1080
#define __MAC_10_9
1090
#define __MAC_10_10
101000
/* __MAC_NA is not defined to a value but is uses as a token by macros to indicate that the API is unavailable */
#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_7_0 70000
#define __IPHONE_7_1 70100
#define __IPHONE_8_0 80000
#define __IPHONE_8_1 80100
#define __IPHONE_8_2 80200
#define __IPHONE_8_3 80300
#define __IPHONE_8_4 80400
/* __IPHONE_NA is not defined to a value but is uses as a token by macros to indicate that the API is unavailable */
我们可以使用这些宏定义
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
// 只能在ios 下
#if __IPHONE_OS_VERSION_MIN_REQUIRED > 40300
//做一些事情
#else
//做一些事情
#endif
#endif
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
// 只能在mac os x
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050
// code in here might run on pre-Leopard OS
#else
// code here can assume Leopard or later
#endif
#endif
相关文章推荐
- 很常用的第三方或者开源库
- 关于BIOS的入口地址0xFFFF0
- Quartz2D
- 强烈推荐的插件(xcode)
- 5042款iOS代码库开源软件
- iOS 心得五 iOS7的适配(特别是单元格的动态适配)
- iOS 传值
- ios 单一线程中的Runloop机制会导致线程安全问题吗?
- iOS AVAudioSession、AudioSession Category选择和声音通道听筒、扬声器切换
- IOS学习之 手势操作
- CAKeyframeAnimation-核心动画-帧动画
- ios 使用block中使用self可能产生的循环引用
- NSUserDefaults 存储可变数组问题
- iOS提交后申请加急审核
- iOS中Bonjour:NSNetServiceBrowser在子线程上使用
- wxhl iOS bj 49 张浩 学习心得文章连载 第14章
- iOS开发总结之代码规范
- 蓝懿学习 练习总结
- <iOS>数据缓存
- 【iOS程序启动与运转】- RunLoop个人小结