Determining the OS version at runtime
01/09/04 09:28
I want to skip some specific calls if the OS is not a defined version. How to ?
If the calls you are targeting are methods of Objective-C classes, it's better to use the method respondsToSelector: to test for the availability of a feature:
if ([aView respondsToSelector:@selector(setHidden:)])
[aView setHidden:YES];
You can also check the NSAppKitVersionNumber
For checking the availability of other kind of calls, you can use Gestalt:
SInt32 theOSVersion = 0;
if (::Gestalt (gestaltSystemVersion, &theOSVersion) != noErr) {
theOSVersion = 0;
}
if (theOSVersion >= 0x00001030L) {
...
There is also the sysctl API that will give you information about the kernel version. See the article at CocoaDevCentral for more info.
if ([aView respondsToSelector:@selector(setHidden:)])
[aView setHidden:YES];
You can also check the NSAppKitVersionNumber
For checking the availability of other kind of calls, you can use Gestalt:
SInt32 theOSVersion = 0;
if (::Gestalt (gestaltSystemVersion, &theOSVersion) != noErr) {
theOSVersion = 0;
}
if (theOSVersion >= 0x00001030L) {
...
There is also the sysctl API that will give you information about the kernel version. See the article at CocoaDevCentral for more info.