Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the OS X system version?

Tags:

macos

cocoa

I want to get the OS X system version, such as: 10.5.4, 10.4.8, etc. I want to get it in my app, how do I do this? Thanks!

like image 444
jin Avatar asked May 20 '09 02:05

jin


2 Answers

You can read the property list at "/System/Library/CoreServices/SystemVersion.plist and extract the "ProductVersion" key, this is how the OS X installer application does it. Here's an example:

NSString *versionString;
NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
versionString = [sv objectForKey:@"ProductVersion"];

Alternatively, the command swvers -productVersion will do the same.

like image 143
altan Avatar answered Sep 28 '22 15:09

altan


You can use Gestalt:

SInt32 version = 0;
Gestalt( gestaltSystemVersion, &version );
BOOL leopard = ( version >= 0x1050 );

if ( leopard )
{
    //draw it this way
}
else
{
    //draw it that way
}

Keep in mind if you're checking if a method is available or not, it's better to test that directly using respondsToSelector:.

like image 23
Marc Charbonneau Avatar answered Sep 28 '22 17:09

Marc Charbonneau