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"
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.
The official and recommend way from Apple is to read /System/Library/CoreServices/SystemVersion.
NSProcessInfo *pInfo = [NSProcessInfo processInfo];
NSString *version = [pInfo operatingSystemVersionString];
Sorry for the formatting, I'm using my iPad to answer this.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With