【问题标题】:macOS version returned as 10.16 instead of 12.0macOS 版本返回为 10.16 而不是 12.0
【发布时间】:2021-09-08 05:46:37
【问题描述】:

我正在新的 macOS 12 Monterey beta 上运行使用 C++ 构建的应用程序。该应用程序是使用相当旧的 macOS SDK 10.9 构建的。

问题: 有一个获取平台版本的代码,我使用 Core-Foundation API 解析 System/Library/CoreServices/SystemVersion.plist 文件的内容。应用程序没有将 macOS 版本返回为 12.0,而是将其读取为 10.16。代码没有缺陷,因为相同的代码已被用于识别许多旧 macOS 版本。

可能的原因: 在 macOS 11.0 bigSur 版本中发生了一些变化,其中有另一个文件名 SystemVersionCompat.plist 与 SystemVersion.plist 位于同一位置。我的应用程序正在阅读前者而不是后来的 plist,并且由于使用了较旧的 SDK,因此在一些网络搜索中了解了它。

System/Library/CoreServices/SystemVersion.plist的内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>ProductBuildVersion</key>
    <string>21A5304g</string>
    <key>ProductCopyright</key>
    <string>1983-2021 Apple Inc.</string>
    <key>ProductName</key>
    <string>macOS</string>
    <key>ProductUserVisibleVersion</key>
    <string>12.0</string>
    <key>ProductVersion</key>
    <string>12.0</string>
    <key>iOSSupportVersion</key>
    <string>15.0</string>
</dict>
</plist>

System/Library/CoreServices/SystemVersionCompat.plist的内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>ProductBuildVersion</key>
    <string>21A5304g</string>
    <key>ProductCopyright</key>
    <string>1983-2021 Apple Inc.</string>
    <key>ProductName</key>
    <string>Mac OS X</string>
    <key>ProductUserVisibleVersion</key>
    <string>10.16</string>
    <key>ProductVersion</key>
    <string>10.16</string>
    <key>iOSSupportVersion</key>
    <string>15.0</string>
</dict>
</plist>

有没有其他方便的方法可以在不更新SDK的情况下获取平台版本?

【问题讨论】:

  • 如果你打开了错误的文件,那么你的代码很可能有问题。不幸的是,我们无法帮助您,因为您没有展示它。也许是时候刷新the help pages,使用SO tour,阅读How to Ask,以及this question checklist。并且不要忘记如何创建一个minimal reproducible example 向我们展示。
  • 是的@AlanBirtles 是正确的,这篇文章准确地定义了我的问题。 macOS 在打开 SystemVersion.plist 文件时会耍花招。我正在寻找不更新 SDK 的解决方法。
  • 为什么不想更新sdk?
  • 10.16 表示 11.0 或更高版本,作为 10.x 和 11.0 之间的过渡点...developer.apple.com/documentation/foundation/… NSOperatingSystemVersion 如果您愿意放弃 10.9 以升级到 10.10,则可以使用该结构。跨度>

标签: c++ macos core-foundation macos-monterey


【解决方案1】:

您可以设置环境变量 SYSTEM_VERSION_COMPAT = 0 (在读取文件之前在 plist 文件或代码本身中) 这会给你正确的版本。

在终端上运行以下命令,您会看到不同之处:

SYSTEM_VERSION_COMPAT=1 cat /System/Library/CoreServices/SystemVersion.plist

SYSTEM_VERSION_COMPAT=0 cat /System/Library/CoreServices/SystemVersion.plist

【讨论】:

  • 这是为我做的,但我希望 Apple 有一些关于 SYSTEM_VERSION_COMPAT 的文档,以便我可以验证版本是 SystemVersion.plist 和 SystemVersionCompat.plist 之间唯一不同的地方。跨度>
猜你喜欢
  • 2022-01-16
  • 1970-01-01
  • 1970-01-01
  • 2021-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-26
相关资源
最近更新 更多