As others have said (and I would choose Steven Fisher's answer), you usually do not want to get the version number.
And if you need to make comparisons only with the main OS X version to the version of the current SDK that you are using, NSAppKitVersionNumber (as in Monolo's answer) is the right way to do this.
If you really need to get the version number for some reason (for example, to record analytics about your users, so you can decide when to stop supporting 10.6.0-10.6.5), here's how to do it:
#import <CoreServices/CoreServices.h> SInt32 majorVersion, minorVersion, bugFixVersion; Gestalt(gestaltSystemVersionMajor, &majorVersion); Gestalt(gestaltSystemVersionMinor, &minorVersion); Gestalt(gestaltSystemVersionBugFix, &bugFixVersion);
For 10.7.3 this gives majorVersion = 10, minorVersion = 7, bugFixVersion = 3.
Documentation 10.7 deleted the paragraph that Gestalt directly suggested as a way to get the OS version, but it's still not out of date or out of date, and there are no other suggestions. In fact, any other way to get this information (parsing is [NSProcessInfo OperatingSystemVersionString], calling sysctlbyname on "kern.osrelease" and converting the Darwin kernel version to OS X version, etc.) is explicitly contraindicated somewhere. So this is the way to do it if you really want it.
Just keep in mind that, as noted in the System 6.0.4 release in 1989, this new API may not be permanent and may be removed in a future version of the OS.
abarnert Jun 15 2018-12-12T00: 00Z
source share