简体   繁体   中英

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

如果您没有自己定义__IPHONE_OS_VERSION_MIN_REQUIRED__IPHONE_OS_VERSION_MIN_REQUIRED最终由编译器设置(通过“AvailabilityInternal.h”中的宏)以匹配您设置的最小iphone操作系统版本,因此您需要确保您的部署目标是设置为早于iOS 5.0的东西。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM