xcode __IPHONE_OS_VERSION_MIN_REQUIRED 不返回部署目标?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10349752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
__IPHONE_OS_VERSION_MIN_REQUIRED does not return deployment target?
提问by SpacyRicochet
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. 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.
我想使用一个只能在 iOS 4.3 及更高版本上运行但仍支持 4.0 及更高版本的类。为了实现这一点,如果我尝试在 iOS 版本低于 4.3 的设备上使用这个类,我会断言。为了避免断言,我通过检查 4.3 方法的可用性来避免代码中的类。部署目标当前设置为 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.
但是,因为断言只会在我在旧设备上运行应用程序时发生,所以我还想在部署目标小于 4.3 时添加警告。我正在尝试使用__IPHONE_OS_VERSION_MIN_REQUIRED
. 但是,这以某种方式不断返回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,这就是我问这个问题的原因。
采纳答案by SpacyRicochet
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
按预期工作。
回答by Michael Dautermann
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.
如果您没有定义__IPHONE_OS_VERSION_MIN_REQUIRED
自己,__IPHONE_OS_VERSION_MIN_REQUIRED
最终由编译器设置(通过“AvailabilityInternal.h”中的宏)以匹配您设置的最低 iphone 操作系统版本,因此您需要确保您的部署目标设置为早于 iOS 5.0 的东西。