APIs to determine OS in mac

Discussion in 'Mac Programming' started by roublesaha, Dec 23, 2008.

  1. roublesaha macrumors newbie

    Joined:
    Dec 22, 2008
    #1
    Hi All

    I have a snippet of code which works in 10.4 but it supported in 10.3.

    Hence i want some APIs to determine the OS , so that the snippet gets executed in the proper OS.

    Also, please let me know if u have any better way to distinguish between the versions programmatically.

    I am working with C++ source code
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    You can call Gestalt() with gestaltSystemVersionMajor and gestaltSystemVersionMinor.
     
  3. roublesaha thread starter macrumors newbie

    Joined:
    Dec 22, 2008
    #3
    thanks........i will try that..

    but i guess that is available in 10.4 onwards....i need for 10.3 and onwards.:(
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Why do you say that? It is supported in 10.3. I am looking at the header file from the 10.3.9 SDK right now :)
     
  5. roublesaha thread starter macrumors newbie

    Joined:
    Dec 22, 2008
    #5
    ok i am also using 10.3.9...

    I am not able to use it properly.Please help me out

    Can u please give an wxample how to use this......
     
  6. roublesaha thread starter macrumors newbie

    Joined:
    Dec 22, 2008
    #7
    But can please u tell me how to do the following :

    I want to compare the value returned by ( NSString *str = [[NSProcessInfo processInfo] operatingSystemVersionString] ) with 10.4

    .If it is less than that execute one piece of code otherwise if it is greater then execute other piece of code.
     
  7. Cool6324 macrumors member

    Joined:
    Sep 18, 2007
    Location:
    Raleigh, NC
    #8
    Check out this method in the NSString Class:

    caseInsensitiveCompare:
    Returns the result of invoking compare:eek:ptions: with NSCaseInsensitiveSearch as the only option.

    - (NSComparisonResult)caseInsensitiveCompare:(NSString *)aString

    I will write it below, but I have not written Cocoa in awhile for forgive me for any mistakes...

    Code:
    NSString *str = [[NSProcessInfo processInfo] operatingSystemVersionString];
    
    if ([str caseInsensitiveCompare:@"10.4.1"] == NSOrderedAscending) {
    
    /*execute some code here.......*/
    
    
    }
    
    You should get the idea.
     
  8. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #9
    That kind of thing broke lots of applications when 10.4.10 was released (and some stupid code believed that 10.4.10 is less than 10.4.3, for example).

    The Gestalt code works.

    developer.apple.com, type in "Gestalt" and see what happens.
    Or start XCode, type "Gestalt" into any file, double click on it to select the word, then right click + select "Show API Reference" or "Show Definition".
     
  9. roublesaha thread starter macrumors newbie

    Joined:
    Dec 22, 2008
    #10
    thanks all for the help...it is working fine now
     

Share This Page