我有一些代码我想只在最新的iPhone SDK(3.0)上执行,但我似乎无法找到一种方法来定位3.0并忽略2.2.1等.有一个ifdef语句,但它似乎覆盖了整个iPhone:
#if TARGET_OS_IPHONE
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
Jan*_*les 89
您可以使用此#define更改为每个SDK构建的内容...
#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_2_2
// iPhone 3.0 code here
#endif
Run Code Online (Sandbox Code Playgroud)
并在运行时执行此操作以运行3.0及更高版本的代码:
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 3.0)
{
// iPhone 3.0 code here
}
Run Code Online (Sandbox Code Playgroud)
小智 19
我要小心floatValue返回结果:
[[[UIDevice currentDevice] systemVersion] floatValue]
Run Code Online (Sandbox Code Playgroud)
与任何花车一样,它可能不完全符合您的预期.在我的系统上运行上面的操作时,弄清楚我的条件语句没有执行的原因,我注意到返回的值是:
3.20000005
Run Code Online (Sandbox Code Playgroud)
这里推荐解决方案:如何检查iOS版本?
摘抄:
NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"3.1.3" options: NSNumericSearch];
if (order == NSOrderedSame || order == NSOrderedDescending) {
// OS version >= 3.1.3
} else {
// OS version < 3.1.3
}
Run Code Online (Sandbox Code Playgroud)
更新:使用Xcode 4在iPhone(4.3.1)上构建和运行时,这似乎对我不起作用.而且,我明白了__IPHONE_OS_VERSION_MIN_REQUIRED = 30200.
iPhone Developer's Cookbook说你也可以这样做:
#ifdef _USE_OS_4_OR_LATER
// code to compile for 4.0 or later
#else
// code to compile for pre-4.0
#endif
Run Code Online (Sandbox Code Playgroud)
而且,它似乎对我有用.:)
| 归档时间: |
|
| 查看次数: |
37462 次 |
| 最近记录: |