如何使用xcode编译器警告来确定最低IOS部署目标

时间:2023-01-23 17:06:38

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

我正在使用Xcode 3.2.5构建iOS应用程序,Base SDK设置为iOS 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.

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

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开发指南,“当Xcode检测到您的应用程序正在使用目标操作系统版本中不可用的功能时,会显示构建警告”。

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部署目标设置为iOS 3.0,我仍然没有收到任何编译器警告。

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?

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

3 个解决方案

#1


3  

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

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

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.

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

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.

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

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.

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

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.

正确的解决方案似乎只是针对以前版本的SDK构建(您可以在模拟器中始终执行此操作),如果使用缺少的API,您将获得Xcode错误。

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

有关详细信息,请阅读此技术说明:http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html

#2


2  

temporarily change your base sdk to see them

暂时更改您的基本sdk以查看它们

#3


0  

Edited: for detecting new APIs that are only available in new versions of iOS, I don't think Xcode can do it automatically for us. We need to put them in our mind by ourselves. My suggested reading source:

编辑:为了检测仅在新版iOS中可用的新API,我不认为Xcode可以自动为我们做。我们需要自己把它们放在我们的脑海里。我建议的阅读来源:

  1. Login into your dev account and search API diffs. These official API diffs documents should be thorough and helpful.
  2. 登录您的开发帐户并搜索API差异。这些官方API差异文档应该是彻底和有用的。
  3. Check this great post on how to wrap up your code to make it compatible on lower versions of iOS:
  4. 查看这篇很棒的帖子,了解如何整理代码以使其与较低版本的iOS兼容:

===

===

Try clean your project's build folder. After that you should see warnings on deprecated APIs that your code used.

尝试清理项目的构建文件夹。之后,您应该看到代码使用的已弃用API的警告。

如何使用xcode编译器警告来确定最低IOS部署目标

如何使用xcode编译器警告来确定最低IOS部署目标

#1


3  

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

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

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.

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

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.

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

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.

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

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.

正确的解决方案似乎只是针对以前版本的SDK构建(您可以在模拟器中始终执行此操作),如果使用缺少的API,您将获得Xcode错误。

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

有关详细信息,请阅读此技术说明:http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html

#2


2  

temporarily change your base sdk to see them

暂时更改您的基本sdk以查看它们

#3


0  

Edited: for detecting new APIs that are only available in new versions of iOS, I don't think Xcode can do it automatically for us. We need to put them in our mind by ourselves. My suggested reading source:

编辑:为了检测仅在新版iOS中可用的新API,我不认为Xcode可以自动为我们做。我们需要自己把它们放在我们的脑海里。我建议的阅读来源:

  1. Login into your dev account and search API diffs. These official API diffs documents should be thorough and helpful.
  2. 登录您的开发帐户并搜索API差异。这些官方API差异文档应该是彻底和有用的。
  3. Check this great post on how to wrap up your code to make it compatible on lower versions of iOS:
  4. 查看这篇很棒的帖子,了解如何整理代码以使其与较低版本的iOS兼容:

===

===

Try clean your project's build folder. After that you should see warnings on deprecated APIs that your code used.

尝试清理项目的构建文件夹。之后,您应该看到代码使用的已弃用API的警告。

如何使用xcode编译器警告来确定最低IOS部署目标

如何使用xcode编译器警告来确定最低IOS部署目标