简体   繁体   English

__IPHONE_OS_VERSION_MIN_REQUIRED不会返回部署目标?

[英]__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? 为什么__IPHONE_OS_VERSION_MIN_REQUIRED返回基本SDK而不是部署目标?

I want to use a class that can only run on iOS 4.3 and greater, but still support 4.0 and greater. 我想使用一个只能在iOS 4.3及更高版本上运行的类,但仍支持4.0及更高版本。 To achieve this, I assert if I try to use this class on devices with an iOS version lower than 4.3. 为了实现这一点,我断言如果我尝试在iOS版本低于4.3的设备上使用此类。 To avoid asserting, I avoid the class in-code by checking for the availability of the 4.3 methods. 为了避免断言,我通过检查4.3方法的可用性来避免类in-code。 The deployment target is currently set to 4.0. 部署目标当前设置为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. 但是,因为断言只会在我在旧设备上运行应用程序时发生,所以如果部署目标小于4.3,我还想添加警告。 I am trying to use __IPHONE_OS_VERSION_MIN_REQUIRED . 我正在尝试使用__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. 然而,这不知何故继续返回50000 (基本SDK)而不是43000以下的东西,我无法弄清楚为什么。

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. 编辑:我的部署目标已设置为4.0,这就是我问这个问题的原因。

如果您没有自己定义__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. 在我的例子中,类的部署目标设置为5.0(而不是我的主项目,设置为4.0),这意味着__IPHONE_OS_VERSION_MIN_REQUIRED按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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