【发布时间】:2015-11-30 13:58:06
【问题描述】:
我想使用以下代码,但仅适用于在 iOS
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if(..)
test()
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
#endif
但是,当我构建代码并在设备上运行它时,该方法不会执行。我做错了什么?该应用程序最低支持 iOS 7.0,也可以在 iOS9 中运行(最新的 xcode 7)
【问题讨论】:
-
你不能像这样使用预处理器宏,因为这是一个编译时特性。您需要运行时检查。
-
为什么不希望为 iOS 9.0 及更高版本调用此委托方法?
-
Maddy 是对的——预处理器检查不是在运行时进行的。所以你的版本要么有这个功能,要么没有。您需要像 trojanfoe 一样的运行时检查。