• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detect legacy OSX
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detect legacy OSX


  • Subject: Re: Detect legacy OSX
  • From: Rosyna <email@hidden>
  • Date: Wed, 22 Aug 2007 13:14:14 -0700

Ack, at 8/22/07, David Duncan said:

// This function checks if we are running on 10.5 or later
BOOL RunningOn105OrLater()

But then you'd have to update it/rename it for every system update. See below for some happy BCD code.


Two things about this code

1) The Gestalt selectors that I'm using only exist on 10.3 or later. You can detect this by checking for errors (which I do not here) and use an alternate selector (gestaltSystemVersion) in that case.

Actually, they're 10.4+ only. It's not documented in the header (which is lame) but is documented in the documentation, <file:///Developer/ADC Reference Library/documentation/Carbon/Reference/Gestalt_Manager/Reference/reference.html#//apple_ref/doc/c_ref/gestaltSystemVersionMinor>


2) Checking the OS version in order to detect features is a technique of LAST resort.

Weak linking, ftw. Gestalt is usually only used (for valid reasons) when you need to know that the system version changed or need to check the system version because the logic or flow of code is completely different (or the previous version has a serious bug in it that prevents the API from being used without skanky workarounds, I'm looking at you Font Panel....).


And please don't parse the SystemVersion property list - it is too easy to get that wrong .


Yes, this is exceedingly evil. As you can tell from the huge amount of apps that broke mysteriously or failed to run when 10.4.10 was released and they required 10.4.7 or later to run.

I did not write this, Steve Christensen did and posted it to Carbon-Dev when this question came up two years ago. But the function has been good to me. And it doesn't fail on systems less than 10.4.

For this example, you'd use:

if (VirtuousCankle_GetSystemVersion()>=0x100500)
     // 10.5, ftw

UInt32 VirtuousCankle_GetSystemVersion()
{
// ex: 10.4.17 -> 0x00100417
static UInt32 sBCDSystemVersion = 0;
if (sBCDSystemVersion == 0)
{
SInt32 majorVersion=0, minorVersion=0, bugFixVersion=0;
if ((Gestalt(gestaltSystemVersionMajor, &majorVersion) == noErr) &&
(Gestalt(gestaltSystemVersionMinor, &minorVersion) == noErr) &&
(Gestalt(gestaltSystemVersionBugFix, &bugFixVersion) == noErr))
{
// as written, this should handle up to OS X 99.99.99
sBCDSystemVersion = ((majorVersion / 10) << 20) |
((majorVersion % 10) << 16) |
((minorVersion / 10) << 12) |
((minorVersion % 10) << 8) |
((bugFixVersion / 10) << 4) |
((bugFixVersion % 10) << 0);
}
else
{
SInt32 systemVersion=0;
if (Gestalt(gestaltSystemVersion, &systemVersion) == noErr)
{
sBCDSystemVersion = ((systemVersion & 0x0000ff00) << 8) |
((systemVersion & 0x000000f0) << 4) |
((systemVersion & 0x0000000f) << 0);
}
}
}
return sBCDSystemVersion;
}


I'm obligated to say "You could just do major * 10000 + minor * 100 + bugfix. It wouldn't be BCD, but then you wouldn't have to switch your numeric view to Hex to read it either"
--



Sincerely, Rosyna Keller Technical Support/Carbon troll/Always needs a hug

Unsanity: Unsane Tools for Insanely Great People

It's either this, or imagining Phil Schiller in a thong.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Detect legacy OSX
      • From: Dave Fernandes <email@hidden>
References: 
 >Detect legacy OSX (From: Andrew James <email@hidden>)
 >Re: Detect legacy OSX (From: David Duncan <email@hidden>)

  • Prev by Date: Re: Detect legacy OSX
  • Next by Date: subpathsAtPath and memory usage
  • Previous by thread: Re: Detect legacy OSX
  • Next by thread: Re: Detect legacy OSX
  • Index(es):
    • Date
    • Thread