objective-c - 在我无法重新编译的框架的运行时找到部署目标

标签 objective-c runtime deployment-target

在编译时使用宏 __IPHONE_OS_VERSION_MIN_REQUIRED 确定应用程序的部署目标非常简单。也可以直接找到应用程序在运行时运行的当前 iOS 版本。我试图在运行时找出应用程序的部署目标。我需要在已经编译的框架中使用它。是否有公共(public) API 方法来确定这一点?我找不到。

只是为了清楚。我希望在运行时从我的框架中获取 iOS 应用程序的部署目标。不是编译时间。在我的框架中,我需要提醒框架的用户,如果他们的部署目标太落后,某些功能将无法工作。

我知道这在编译时很容易做到,但我的框架已经编译,我不想要求框架的用户在他们的代码中为我的框架添加宏来确定他们的部署目标。

最佳答案

这是一个老问题,但我刚刚验证了答案,所以这里是:

在 iOS 上,您应该使用 Info.plist 中的 MinimumOSVersion 键来查找运行时支持的最低版本。

来源其实是linked from the documentationJosh Caswell posted , 关于 LSMinimumSystemVersion

请注意,文档解释说,作为开发人员,您不应自己设置 MinimumOSVersion 值,并且 Xcode 在构建期间会自动为您填充该值。这解释了 rather cryptic "Do Not Use"在本文档的另一部分。

在此处发布此 key 的描述,以备后代使用(2016 年 12 月),以防文档发生更改:

MinimumOSVersion (String - iOS). When you build an iOS app, Xcode uses the iOS Deployment Target setting of the project to set the value for the MinimumOSVersion key. Do not specify this key yourself in the Info.plist file; it is a system-written key. When you publish your app to the App Store, the store indicates the iOS releases on which your app can run based on this key. It is equivalent to the LSMinimumSystemVersion key in macOS.

我通过打印出测试应用程序中的值(并将 Xcode 项目的部署目标更改为不同的值)验证了这一点:

if let infoPlist = Bundle.main.infoDictionary {
  let minimumVersion = infoPlist["MinimumOSVersion"]
  if let minimumVersion = minimumVersion {
    print("Minimum version is \(minimumVersion)")
  }
}

关于objective-c - 在我无法重新编译的框架的运行时找到部署目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25313234/

相关文章:

objective-c - 提取包含关键字的句子 Objective c

ios - 如何避免 "Terminating app due to uncaught exception"

ios - 仅Monotouch风景iOS6

ios - 无法验证适用于 iOS App Store 的应用程序,缺少 armv6 架构

objective-c - iPad 应用程序中的垂直 UINavigationBar

ios - PFQuery 的奇怪行为

ios - 我怎样才能得到 objc_property_t 类型

objective-c - 在运行时获取类的类别详细信息?

c# - 将 IList 转换为 SomeType[]