在Cocoa中检查OS X版本 [英] OS X version checking in Cocoa

查看:135
本文介绍了在Cocoa中检查OS X版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Cocoa应用程序,需要检查当前的OS X版本是否为OS X 10.6 Snow Leopard

I am developing a Cocoa application and need to check whether the current OS X version is OS X 10.6 Snow Leopard

如果当前版本是Snow Leopard,

If the current version is Snow Leopard, I need to close the application with an error alert.

如何找到当前的OS X版本?

How can I find the current OS X version?

推荐答案

相关的Apple文档可以在使用基于SDK的开发中找到:确定框架的版本

The relevant Apple documentation can be found in Using SDK-Based Development: Determining the Version of a Framework.

他们建议测试一个特定类或方法的存在,或者检查框架版本号,例如 NSAppKitVersionNumber NSFoundationVersionNumber 。相关框架还声明了不同操作系统版本的多个常量( NSApplication constants Foundation Constants )。

They suggest either testing the existence of a specific class or method or to check the framework version number, e.g. NSAppKitVersionNumber or NSFoundationVersionNumber. The relevant frameworks also declare a number of constants for different os versions (NSApplication constants, Foundation Constants).

相关代码可以如下简单:

The relevant code can be as simple as:

if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) {
    // Code for 10.6+ goes here
}

这篇关于在Cocoa中检查OS X版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆