如何使用xcode编译器警告来确定最低IOS部署目标 [英] How to use xcode compiler warnings to determine minimum IOS deployment target

查看:134
本文介绍了如何使用xcode编译器警告来确定最低IOS部署目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xcode 3.2.5构建一个iOS应用程序,Base SDK设置为iOS 4.2

I'm building an iOS app using Xcode 3.2.5 with the Base SDK set to iOS 4.2

我知道我已经使用了4.0和4.1中的一些api但不确定我是否真的需要4.2。

I know I've used some api's from 4.0 and 4.1 but not sure about whether I actually require 4.2.

根据iOS开发指南,当Xcode检测到您的应用程序使用的功能不可用时会显示构建警告在目标操作系统版本中。

According to the iOS Development Guide, "Xcode displays build warnings when it detects that your application is using a feature that’s not available in the target OS release".

所以我希望使用编译器警告来获得我的最低操作系统要求。
但是,即使我将iOS部署目标设置为iOS 3.0,我仍然没有收到任何编译器警告。

So I was hoping to use the compiler warnings to derive my minimum OS requirement. However, even when I set my iOS Deployment Target to iOS 3.0, I still don't get any compiler warnings.

我一定做错了,但不确定是什么?任何人都可以确认当iOS部署目标小于基本SDK并且代码使用基本SDK功能时,他们会收到编译器警告吗?或者编译器警告只显示你是否链接了iOS部署目标版本中不存在的框架?

I must be doing something wrong, but not sure what? Can anyone confirm that they get compiler warnings when the iOS deployment target is less than the base SDK and the code uses base SDK functions? Or do the compiler warnings only show if you link a framework that didn't exist in the iOS deployment target version?

推荐答案

它是行为符合预期:更改部署目标会影响您应用运行的最低操作系统版本,而不是最大值。

It's behaving as expected: changing the deployment target only affects the minimum OS version you app will run on, not the maximum.

如果您使用4.3 SDK并将部署目标设置为4.0,这意味着您的应用程序将硬连接任何4.0之前的API并弱化4.0和4.3之间引入的任何API。您必须在运行时检查是否存在API(例如,C函数的空指针)或操作系统版本。

If you use the 4.3 SDK and set the deployment target to 4.0, it just means your app will hard-link any pre-4.0 APIs and weak-link any APIs introduced between 4.0 and 4.3. You have to check at runtime either for the existence of the API (e.g. null pointer for C functions) or the OS version.

部署目标确实生成Xcode警告但是不推荐使用的API:例如,如果您使用4.1及更高版本中弃用的API且部署目标是4.1或更高版本,则会收到警告,但如果是4.0或更早版本,则不会。

The deployment target does generate Xcode warnings but for deprecated APIs: for example if you use an API deprecated in 4.1 and later and the deployment target is 4.1 or later, you get a warning, but if it's 4.0 or earlier, you don't.

在您的情况下,您真正​​需要的是相当于 MAC_OS_X_VERSION_MAX_ALLOWED (它不是默认构建设置的一部分,但您可以自定义它它应该覆盖SDK设置的值,但适用于iOS SDK。我不确定它是否正式存在:我能够找到 __ IPHONE_OS_VERSION_MAX_ALLOWED ,但考虑到它以 __ 开头,我不确定它是否真的受到支持。

It looks like what you really need in your case is the equivalent of MAC_OS_X_VERSION_MAX_ALLOWED (it's not part of the default build settings, but you can custom define it and it should override the value set by the SDK) but for iOS SDK. I'm not sure it officially exists actually: I was able to find a __IPHONE_OS_VERSION_MAX_ALLOWED but considering it starts with __, I'm not sure it's really supported.

正确的解决方案似乎只是针对以前版本的SDK构建(你总是可以在模拟器中这样做),你会如果使用缺少的API,则会出现Xcode错误。

The right solution appears to simply build against previous versions of the SDK (you can always do that in the Simulator) and you will get Xcode errors if using missing APIs.

欲了解更多信息,请阅读以下技术说明: http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html

For more info, read this technote: http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html

这篇关于如何使用xcode编译器警告来确定最低IOS部署目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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