运行时与编译时iPhone版本检查 [英] run-time vs. compile-time iPhone version check

查看:140
本文介绍了运行时与编译时iPhone版本检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行时之间有什么区别,例如 [[UIDevice currentDevice] systemVersion] 和编译时间,例如 __ IPHONE_OS_VERSION_MIN_REQUIRED 检查?什么时候你应该在另一个上面?

What's the difference between run-time, e.g., [[UIDevice currentDevice] systemVersion], and compile-time, e.g., __IPHONE_OS_VERSION_MIN_REQUIRED checking? When should you one over the other?

__ IPHONE_OS_VERSION_MIN_REQUIRED 只是在Build Settings中设置的变量?

Is__IPHONE_OS_VERSION_MIN_REQUIRED just a variable set in Build Settings?

我已经阅读了的答案如何定位特定的iPhone版本?以及下面列出的其他相关问题。

I've read the answers to How to target a specific iPhone version? and other related questions listed below.

但是,我只是注意到 __ IPHONE_OS_VERSION_MIN_REQUIRED = 30200 当我建立&使用Xcode 4在iPhone(4.3.1)上运行。为什么?

But, I just noticed that __IPHONE_OS_VERSION_MIN_REQUIRED = 30200 when I build & run on iPhone (4.3.1) with Xcode 4. Why?

当您向Apple提交代码时,他们是否为每个版本的iPhone编译了一个版本的代码存在,相应地设置 __ IPHONE_OS_VERSION_MIN_REQUIRED

When you submit your code to Apple, do they compile a version of it for each version of the iPhone that exists, setting __IPHONE_OS_VERSION_MIN_REQUIRED accordingly?

这样,你可以检查 __ IPHONE_OS_VERSION_MIN_REQUIRED ,并知道iOS版本正在运行代码。

That way, you could inspect __IPHONE_OS_VERSION_MIN_REQUIRED, and know what iOS version is running the code.

  • How to check iOS version?
  • Check iOS version at runtime?
  • How to check if iOS version supports library?

推荐答案

__ IPHONE_OS_VERSION_MIN_REQUIRED 确实只是一个建立设置,你可以在预处理器中使用在编译之前修改代码。不,Apple不为每个iPhone编译代码。他们不能,因为你没有给他们代码。例如,您可以使用编译时检查来确定是否需要编译代码以模拟旧版OS中的新功能。但是,您使用运行时版本检查来确定是否应使用该功能的内置版本或模拟版本。

__IPHONE_OS_VERSION_MIN_REQUIRED is indeed just a build setting, which you can use in the preprocessor to modify code before compilation. No, Apple doesn't compile your code for each iPhone. They can't, since you don't give them the code. You can use compile time checking to determine, for example, if you need to compile code to emulate a new feature in older OS versions. However, you use runtime version checking to determine whether you should use the built in or emulated version of that feature.

例如,iAds是在4.0中添加的。您目前支持4.0及更高版本,但计划在将来添加对3.2的支持。您可以使用运行时检查来确定是否应该使用iAds或其他广告来制作代码以显示旧版本中的其他广告,但是在应用程序的其余部分准备好3.2之前,您不希望它出现在任何版本中,因为它会让你的应用更大。您使用编译时检查,以便预处理器将该代码保留在您的版本之外。通过使用最小版本宏,您可以通过更改最低版本构建设置轻松地将代码添加到您的版本。

For example, iAds were added in 4.0. You currently support 4.0 and later, but plan on adding support for 3.2 in the future. You make code to display other ads in older versions, using runtime checking to determine whether you should use iAds or other, but you don't want it to be in any releases until the rest of the application is ready for 3.2, since it will make your application larger. You use compile time checking so that the preprocessor leaves that code out of your releases. By using the minimum version macro, you can easily add the code to your release by changing the minimum version build setting.

这篇关于运行时与编译时iPhone版本检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆