Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get OSX version with objective-c

How would I be able to get the OSX version in objective-c? I would like to avoid using shell commands. E.g "10.5" or "10.4"

like image 429
alexyorke Avatar asked Sep 12 '10 13:09

alexyorke


People also ask

How do I find my OS version in Objective C?

An example code below dumps the iOS version and checks whether the version is greater than or equal to 6.0. // Get the system version of iOS at runtime. NSString *versionString = [[UIDevice currentDevice] systemVersion]; // Convert the version string to a Version instance.

How do I find runtime version on Mac?

The official and recommend way from Apple is to read /System/Library/CoreServices/SystemVersion.


2 Answers

NSProcessInfo *pInfo = [NSProcessInfo processInfo];
NSString *version = [pInfo operatingSystemVersionString];

Sorry for the formatting, I'm using my iPad to answer this.

like image 185
ennuikiller Avatar answered Oct 15 '22 19:10

ennuikiller


As of 10.10 you can use NSProcessInfo.processInfo.operatingSystemVersion to get a NSOperatingSystemVersion struct.

typedef struct {
    NSInteger majorVersion;
    NSInteger minorVersion;
    NSInteger patchVersion;
} NSOperatingSystemVersion;

There's also a helpful isOperatingSystemAtLeastVersion: method.

NSOperatingSystemVersion minimumSupportedOSVersion = { .majorVersion = 10, .minorVersion = 12, .patchVersion = 0 };
BOOL isSupported = [NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:minimumSupportedOSVersion];
like image 8
Jenn Avatar answered Oct 15 '22 20:10

Jenn