Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OS X version checking in Cocoa

Tags:

macos

cocoa

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

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

How can I find the current OS X version?

like image 805
MobX Avatar asked Jan 22 '10 06:01

MobX


People also ask

How do I check my Mac OS version?

From the Apple menu  in the corner of your screen, choose About This Mac. You should see the macOS name, such as macOS Monterey or macOS Big Sur, followed by its version number. If you need to know the build number as well, click the version number to see it.


1 Answers

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

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
}
like image 124
Adrian Avatar answered Sep 22 '22 14:09

Adrian