How to get the OS X system version?

后端 未结 8 1911
一整个雨季
一整个雨季 2021-01-31 11:45

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!

相关标签:
8条回答
  • 2021-01-31 12:02

    After 10_10, 8_0 were presented the better & simplest way would be
    [NSProcessInfo processInfo].operatingSystemVersion
    which will return
    NSOperatingSystemVersion struct
    with all 3 numbers.

    0 讨论(0)
  • 2021-01-31 12:03

    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.

    0 讨论(0)
  • 2021-01-31 12:11

    use this method it will return Mac OS X version

    +(SInt32) OSVersion;
    {
        SInt32 osxMinorVersion;
        Gestalt(gestaltSystemVersionMinor, &osxMinorVersion);
        return osxMinorVersion;
    } 
    
    0 讨论(0)
  • 2021-01-31 12:12

    Again, you can use Gestalt. Look at the documentation for more information; specifically, you'll want to pass the gestaltSystemVersionMajor, gestaltSystemVersionMinor, and gestaltSystemVersionBugFix constants in the "System Version Constants" portion of the Gestalt Manager Reference documentation

    0 讨论(0)
  • 2021-01-31 12:13

    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:.

    0 讨论(0)
  • 2021-01-31 12:16

    -[NSProcessInfo operatingSystemVersionString] is human readable and localized. Appropriate for displaying to user or using in bug emails and such, but not appropriate for parsing.

    0 讨论(0)
提交回复
热议问题