1

I have a Cocoa app which has different features in Mac OS 10.7 and 10.8 (The deployment target is 10.7). For example, in 10.8 I have a button for Sharing Service while in 10.7 the button is hidden.

The problem here is how can I know which kind of Mac OS is there while my app is running. For iOS, I can get it from UIDevice. But for Cocoa, I don't find the similar class.

Currently, I detect the OS using:


- (BOO)isServiceAvalable
{
   if (NSClassFromString(@"A_Unique_Class_In_One_OS"))
    {
        return YES;
    }
    return NO;
}

I hope there is more elegant way to do it.

tshepang
  • 12,111
  • 21
  • 91
  • 136
scorpiozj
  • 2,687
  • 5
  • 34
  • 60
  • Kindly check these SO questions http://stackoverflow.com/questions/885911/how-to-get-the-mac-os-x-system-version http://stackoverflow.com/questions/157759/how-can-i-determine-the-running-mac-os-x-version-programmatically – Anoop Vaidya Dec 05 '12 at 07:05
  • If you wish to do backward compatibility then... Set the Base SDK to Current version of Mac (ex. 10.7) Set the Deployment SDK to older version (ex.1.4) – Anoop Vaidya Dec 05 '12 at 07:06
  • @AnoopVaidya,Gestalt is deprecated in Mac OS 10.8. – scorpiozj Dec 05 '12 at 07:08
  • few others will be there, i simply googled and found many links, i copied only 2 of them :) – Anoop Vaidya Dec 05 '12 at 07:10

2 Answers2

0
Community
  • 1
  • 1
Jay
  • 6,572
  • 3
  • 37
  • 65
0

If Gestalt is deprecated as scorpiozj mentions then here's a simple NSApplescript way to do it...

NSString* getSystemVersion() {
    NSString* returnString = nil;
    NSString* cmd = @"return system version of (get system info)";
    NSAppleScript* theScript = [[NSAppleScript alloc] initWithSource:cmd];
    NSDictionary* errorDict = nil;
    NSAppleEventDescriptor* result = [theScript executeAndReturnError:&errorDict];
    [theScript release];
    if (errorDict) {
        returnString = [NSString stringWithFormat:@"Error:%@ %@", [errorDict valueForKey:@"NSAppleScriptErrorNumber"], [errorDict valueForKey:@"NSAppleScriptErrorMessage"]];
    } else {
        returnString = [result stringValue];
    }
    return returnString;
}
regulus6633
  • 18,848
  • 5
  • 41
  • 49