Re: Determining OS at Runtime
Re: Determining OS at Runtime
- Subject: Re: Determining OS at Runtime
- From: Steve Christensen <email@hidden>
- Date: Thu, 02 Jul 2009 17:04:46 -0700
On Jul 2, 2009, at 4:29 PM, Steve Christensen wrote:
On Jul 1, 2009, at 5:22 PM, Sherm Pendley wrote:
On Wed, Jul 1, 2009 at 7:24 PM,
iseecolors<email@hidden> wrote:
I need to support 10.4 in my application, but it uses some Carbon
APIs that
are deprecated in 10.5 and I am using some new 10.5 APIs that
require the
10.5 SDK.
I am sure I have seen this before, but I have been unable to find
it in the
Archive. How do I determine at runtime which OS version I am
running on?
Just check for the presence of the function you want to call. In
Xcode, set your deployment target to 10.4, so that Leopard-only
symbols will be weak-linked. Then just check the symbol for NULL
before calling it:
if (SomeLeopardFunction != NULL) {
SomeLeopardFunction();
} else {
TigerFunction();
}
If you want to make sure that you don't include any "old" code in
your executable when you decide to make 10.5 (for example) your
base OS version, you could arrange your code like this:
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
if (SomeLeopardFunction == NULL)
TigerFunction();
else
#endif
SomeLeopardFunction();
...then the compiler will take care of sorting out the details for
you. If you use that sequence in several places, it might even be
worthwhile to create an inline wrapper function in a header file so
the OS-specific details are kept in one place:
inline void SomeFunction()
{
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
if (SomeLeopardFunction == NULL)
TigerFunction();
else
#endif
SomeLeopardFunction();
}
After I sent the message, I realized that a better situation for your
case would be to use
#ifndef NSAppKitVersionNumber10_5
#define NSAppKitVersionNumber10_5 949
#endif
if (NSAppKitVersionNumber < NSAppKitVersionNumber10_5)
...
since it will only use the Tiger method on Tiger.
steve
_______________________________________________
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