简体   繁体   English

确定最低的iOS / macOS部署目标的最佳方法

[英]Best way to determine lowest possible iOS / macOS deployment target

Is there a way to, given an iOS or macOS codebase, determine the lowest possible IPHONEOS_DEPLOYMENT_TARGET or MACOSX_DEPLOYMENT_TARGET I can safely set for a project, in order to capture the largest potential number of supported devices? 在给定iOS或macOS代码库的情况下,是否MACOSX_DEPLOYMENT_TARGET我可以安全地为项目设置的最低IPHONEOS_DEPLOYMENT_TARGETMACOSX_DEPLOYMENT_TARGET ,以便捕获最大数量的受支持设备? I don't want to just arbitrarily say "iOS 11" or something because that would leave users of older operating systems out. 我不想随便说“ iOS 11”之类的东西,因为那样会把旧操作系统的用户拒之门外。 On the other hand, every API call requires a certain version of the OS, and I don't have an accounting of every single API call I make, nor do I want to look them all up. 另一方面,每个API调用都需要特定版本的操作系统,而且我没有记下我进行的每个API调用,也不想查看所有这些API。

For example, maybe one out of the thousands of APIs my app calls requires iOS 10 and will fail on iOS 9. Is there a way to tell? 例如,我的应用程序调用的数千个API中可能只有一个需要iOS 10,而在iOS 9上将失败。有没有办法告诉我? Just setting IPHONEOS_DEPLOYMENT_TARGET to 8.0 seems to compile fine (no warnings), but that doesn't necessarily mean I'm good to deploy on 8.0 devices. 仅将IPHONEOS_DEPLOYMENT_TARGET设置为8.0似乎可以编译正常(无警告),但这并不一定意味着我可以在8.0设备上进行部署。

This similar 8-year-old question suggests there was no such tool to at the time. 这个类似的已有8年历史的问题表明,当时还没有这种工具。 Wondering if anything has changed since. 想知道此后是否有任何变化。

Xcode 10 (and Xcode 9) will warn you if you have any APIs in use that may be an issue. 如果您正在使用任何可能会出现问题的API,则Xcode 10(和Xcode 9)会警告您。 For example, if your Deployment Target is set to iOS 11 and you attempt to use an API added in iOS 12, Xcode will warn you. 例如,如果您的“部署目标”设置为iOS 11,并且您尝试使用iOS 12中添加的API,则Xcode会警告您。

So update your project's or target's Deployment Target to whatever you want and let Xcode give you warnings about such APIs or even deprecated APIs. 因此,将项目或目标的“部署目标”更新为所需的任何内容,并让Xcode向您发出有关此类API甚至不推荐使用的API的警告。

Then you can use the "fix" button on the warning to add the appropriate if (@available ...) check around the newer API and then you can add whatever code is needed in the else to support the older iOS version. 然后,您可以使用警告上的“修复”按钮添加适当的if (@available ...)检查较新的API,然后可以添加else所需的任何代码以支持较旧的iOS版本。

If you feel you got too many such API issues, change your Deployment Target as desired. 如果您觉得这样的API问题太多,请根据需要更改部署目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM