Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Marimuthu

macrumors member
Original poster
Oct 18, 2010
43
0
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)?
 
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)?

The proper answer is that there is no good way.

Take a look at this article:
http://cocoadevcentral.com/articles/000067.php
 
Last edited:
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?

It's not a published API, so no.

Personally I think I would just capture to output of /usr/bin/sw_vers -productVersion.
 
Last edited:
It's not a published API, so no.

Personally I think I would just capture to output of /usr/bin/sw_vers -productVersion.

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.
 
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.

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.

/usr/bin/sw_vers -productVersion
 
If so will the below mentioned technique guarantee reliability.

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?
 
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.

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.
 
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.

Gestalt is Carbon though. No 64-bit support.
 
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

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.