How to use xcode compiler warnings to determine minimum IOS deployment target

爱⌒轻易说出口 提交于 2019-11-27 02:41:54

问题


I'm building an iOS app using Xcode 3.2.5 with the Base SDK set to 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.

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".

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.

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?


回答1:


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.

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.

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.

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.

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




回答2:


temporarily change your base sdk to see them




回答3:


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:

  1. Login into your dev account and search API diffs. These official API diffs documents should be thorough and helpful.
  2. Check this great post on how to wrap up your code to make it compatible on lower versions of iOS:

===

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



来源:https://stackoverflow.com/questions/4688333/how-to-use-xcode-compiler-warnings-to-determine-minimum-ios-deployment-target

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!