Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Mac OS X version number in objective c

How can I find the version number of Mac OS X (eg. "10.6.7") from my Cocoa Objective-C application?

like image 815
AmaltasCoder Avatar asked Jun 27 '11 11:06

AmaltasCoder


People also ask

How do I find my OS version in Objective-C?

In Objective-C, you need to check the system version and perform a comparison. [[NSProcessInfo processInfo] operatingSystemVersion] in iOS 8 and above.

How do I find my macOS X 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.

Is OSX written in Objective-C?

Objective-C was the standard programming language supported by Apple for developing macOS (which descended from NeXTSTEP) and iOS applications using their respective application programming interfaces (APIs), Cocoa and Cocoa Touch, until the introduction of Swift in 2014.


2 Answers

You could use the same technique that Apple's code uses...

NSDictionary *systemVersionDictionary =
    [NSDictionary dictionaryWithContentsOfFile:
        @"/System/Library/CoreServices/SystemVersion.plist"];

NSString *systemVersion =
    [systemVersionDictionary objectForKey:@"ProductVersion"];

Apple does exactly this to fill in the version number for various system utilities in the function _CFCopySystemVersionDictionary here:

http://opensource.apple.com/source/CF/CF-744/CFUtilities.c

like image 67
Matt Gallagher Avatar answered Oct 02 '22 03:10

Matt Gallagher


For OS X 10.10+ I think using NSProcessInfo is an easier and safer way to do that:

NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
NSLog([NSString stringWithFormat:@"%ld.%ld.%ld", version.majorVersion, version.minorVersion, version.patchVersion]);
like image 22
taichino Avatar answered Oct 02 '22 05:10

taichino