如何以编程方式确定正在运行的 Mac OS X 版本?
我有一个程序,它在 Tiger 上的行为需要与 Leopard 上的行为略有不同。 有谁知道一个系统调用可以让我准确地确定正在运行的 Mac OS XI 版本。 我找到了许多宏定义来确定构建机器的操作系统,但没有什么真正能很好地确定运行机器的操作系统。
谢谢, 乔
I have a program which needs to behave slightly differently on Tiger than on Leopard. Does anybody know of a system call which will allow me to accurately determine which version of Mac OS X I am running. I have found a number of macro definitions to determine the OS of the build machine, but nothing really good to determine the OS of the running machine.
Thanks,
Joe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
在此处查看这篇文章
但简而言之,如果您使用碳,请使用 Gestalt()调用,如果你使用的是 cocoa,有一个名为 NSAppKitVersionNumber 的常量,你可以简单地检查它。
编辑:对于 Mac OSX 10.8 及更高版本,不要再使用 Gestalt()。 有关更多详细信息,请参阅此答案:如何在 OS X 或 iOS 中确定运行时的操作系统版本(不使用 Gestalt)?
See this article here
But in short, if you're using carbon, use the Gestalt() call, and if you're using cocoa, there is a constant called NSAppKitVersionNumber which you can simply check against.
Edit: For Mac OSX 10.8 and above, don't use Gestalt() anymore. See this answer for more details: How do I determine the OS version at runtime in OS X or iOS (without using Gestalt)?
您能检查一下是否存在某种功能吗? 例如:
或者
你知道操作系统会做你需要它做的事情,而不是苹果的产品营销团队给它一个特定的数字;-)
Could you just check for the presence of a capability? For instance:
or
then you know that the operating system does what you need it to do, not that Apple's product marketing group gave it a particular number ;-)
API 通过 Gestalt Manager 实现。
请参阅 CocoaDev 站点中的“确定操作系统版本”。
The API is through the Gestalt Manager.
See "Determining OS Version" in the CocoaDev site.
在终端中:
给出:
或:
给出:
In terminal:
Gives:
Or:
Gives:
操作系统版本真的是您想要的吗? 可能有更合适的东西需要测试,例如特定框架的存在或版本号。
Is the OS version really what you want? There may be a more appropriate thing to test for, such as the presence of, or version number of, a particular framework.
在您的程序中,您可以使用格式塔。 这是我的程序用于获取操作系统版本的代码。
within your program you can use Gestalt. Here is the code I am using for my program to obtain the OS version.
respondsToSelector:
几乎肯定比您维护一个给定版本实现和未实现的内容的表格更好。偷懒。 让运行时告诉您它是否可以执行某些操作,并在需要时回退到旧方法。 您的代码将不再那么脆弱,因为您不必维护自己的全局数据,而其余代码必须不断检查这些数据。
respondsToSelector:
almost certainly is better than you maintaining a table of what given releases do and do not implement.Be lazy. Let the runtime tell you whether it can do something or not, and fall back to older methods when you need to. Your code will be far less fragile because you don't have to maintain your own global data that the rest of your code has to keep checking with.
在命令行中运行此命令:
Run this in the command line: