SpacyRicochet
SpacyRicochet

Reputation: 2279

__IPHONE_OS_VERSION_MIN_REQUIRED does not return deployment target?

Why does __IPHONE_OS_VERSION_MIN_REQUIRED return the base SDK instead of the deployment target?

I want to use a class that can only run on iOS 4.3 and greater, but still support 4.0 and greater. To achieve this, I assert if I try to use this class on devices with an iOS version lower than 4.3. To avoid asserting, I avoid the class in-code by checking for the availability of the 4.3 methods. The deployment target is currently set to 4.0.

However, because the asserts would only happen when I run the application on an old device, I also want to add a warning if the deployment target is less than 4.3. I am trying to use __IPHONE_OS_VERSION_MIN_REQUIRED. However, this somehow keeps returning 50000 (the base SDK) instead of something below 43000 and I can't figure out why.

Code:

NSLog(@"Deployment target: %i", __IPHONE_OS_VERSION_MIN_REQUIRED); // Returns 50000 instead of 40000.
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 43000
// Never gets here
NSLog(@"%@", @"WARNING! NWMethodWrapper does not work on iOS versions below 4.3. If you insist on supporting older iOS versions, make sure you do not call NWMethodWrapper methods unless dlsym(RTLD_DEFAULT,\"imp_implementationWithBlock\") evaluates to true.");
#endif
NSAssert(dlsym(RTLD_DEFAULT,"imp_implementationWithBlock"), @"NWMethodWrapper uses methods that are only available from iOS 4.3 and later."); // Asserts, as appropriate (running on iOS 4.2.1).

Edit: My deployment target is already set to 4.0, which is why I'm asking the question.

Upvotes: 3

Views: 11688

Answers (2)

SpacyRicochet
SpacyRicochet

Reputation: 2279

You have to be sure that the Class which is behaving like this is actually part of the project in question and not part of another project, which is accessed through a workspace. These project can be set to their own deployment targets, which do not have to be the same as the one you might be expecting in the main project.

In my case, the deployment target of the class was set to 5.0 (as opposed to my main project, which was set to 4.0), which means that __IPHONE_OS_VERSION_MIN_REQUIRED works as expected.

Upvotes: 3

Michael Dautermann
Michael Dautermann

Reputation: 89559

If you don't define __IPHONE_OS_VERSION_MIN_REQUIRED yourself, __IPHONE_OS_VERSION_MIN_REQUIRED is ultimately set by the compiler (via a Macro in "AvailabilityInternal.h") to match what you have your minimum iphone OS version set to, so you need to make sure your deployment target is set for something earlier than iOS 5.0.

Upvotes: 3

Related Questions