Reliable way to get current OS Version in MAC.

Discussion in 'Mac Programming' started by Marimuthu, Oct 18, 2011.

  1. Marimuthu macrumors member

    Joined:
    Oct 18, 2010
    #1
    Hi All,

    I am working on Snow Leopard and work for a product based company. In one of our company's product, in the About box I need to display the current MAC OS Version.

    Wanted to know if using the "SystemVersion.plist" method to determine the OS Name and version is the most reliable method available?

    Code:
    NSString *versionString;
    	NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
    	versionString = [sv objectForKey:@"ProductVersion"];
    I want to avoid making use of technique where major,minor versions are used to determine the current OS version as this method requires often requires formatting hardcoded strings to generate OS Version.

    The above-mentioned code will give us the current OS Version as a string which can be displayed as it is. I can also determine the product name ProductName = "Mac OS X" from the above dictionary which i also display.

    Can I safely use this approach for current and future version of MAC (Lion and higher version of MAC which might be released in near future)?
     
  2. MorphingDragon, Oct 18, 2011
    Last edited: Oct 18, 2011

    MorphingDragon macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #2
    The proper answer is that there is no good way.

    Take a look at this article:
    http://cocoadevcentral.com/articles/000067.php
     
  3. Marimuthu thread starter macrumors member

    Joined:
    Oct 18, 2010
    #3
    In that case, can I be assured of backward compatibility of the above mentioned technique of acquiring the OS version info when the newer version of MAC OS is released?
     
  4. jiminaus, Oct 18, 2011
    Last edited: Oct 18, 2011

    jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #4
    It's not a published API, so no.

    Personally I think I would just capture to output of /usr/bin/sw_vers -productVersion.
     
  5. Marimuthu thread starter macrumors member

    Joined:
    Oct 18, 2010
    #5
    Correct me if I am wrong, but i believe that I am not using any unpublished API's to get the version info.

    I am getting the info by loading an raw SystemVersion.plist file as illustrated in the code in my earlier post.
     
  6. Marimuthu thread starter macrumors member

    Joined:
    Oct 18, 2010
    #6
    Now i think I understand as to what you meant by "It's not a published API, so no.".
    This technique has not be documented by apple hence is not fool proof and might be modified in newer versions of the OS. Is my understanding right?

    If so will the below mentioned technique guarantee reliability.

     
  7. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #7
    Well, also no. How can anyone guarantee future compatibility? Who knows what will change. You can only place your bet and "hope" for the best.

    But does it really matter? If you're a registered Mac developer, you get access to beta versions of Mac OS X for a very good reason. It's so you can test and update your programs to be compatible with the new version.

    If Apple breaks your technique for detecting the Mac OS X version, then you update the about box code and release an update of your program. Why the big deal over an about box? Or are we not actually talking about an about box?
     
  8. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #8
    Three calls to the "Gestalt" function with parameters gestaltSystemVersion, gestaltSystemVersionMinor and gestaltSystemVersionBugFix.

    For example, on 10.7.2 these calls will return 10, 7, and 2. On 10.4.11 (I think that was the highest sub version ever) they returned 10, 4, and 11.

    I haven't found anything equivalent on iOS, but I didn't look too close.
     
  9. MorphingDragon macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #9
    Gestalt is Carbon though. No 64-bit support.
     
  10. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #10
    My understanding was that there was no 64-bit support for the Carbon GUI classes but a large amount of the non-GUI Carbon API was 64-bit compatible where no alternative existed. Could be wrong though
     
  11. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #11
    You are right. Gestalt() is valid under 64-bit, it's part of CoreServices which is 64-bit. Even some things in Carbon.framework are 64-bit still but HIToolbox is what most people mean when they say Carbon and that is 32-bit.

    Gestalt() is the way to go as it's the most direct API in providing marketing version numbers.

    Take a look at Apple's Determining the Version of the Operating System or a Framework.
     

Share This Page