根据设备iOS为iOS添加条件代码

根据设备iOS为iOS添加条件代码,ios,ios9,Ios,Ios9,我想使用以下代码,但仅适用于在iOS

我想使用以下代码,但仅适用于在iOS<9中运行的设备。特别是我想在一个有iOS8的设备上运行它

#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
#如果允许的IPHONE操作系统版本最大值<90000
-(UIInterfaceOrientationTask)应用程序:(UIApplication*)应用程序支持InterfaceOrientationsforWindow:(UIWindow*)窗口的接口方向
{
NSString*currSysVer=[[UIDevice currentDevice]systemVersion];
如果(…)
测试()
返回UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
#恩迪夫

但是,当我构建代码并在设备上运行它时,该方法不会执行。我做错了什么?该应用程序至少支持7.0版的iOS操作系统,也可以在iOS9中运行(最新的xcode 7)

您需要删除
\if\u IPHONE\u OS\u版本\u MAX\u允许<90000
\endif
,然后我认为这可以做到:

float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version < 9.0f)
    test()
float version=[[UIDevice currentDevice]systemVersion]floatValue];
如果(版本<9.0f)
测试()
使用此“系统版本控制预处理器宏”检查系统版本

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

对于iOS9,我应该使用什么来代替v?9000?@cateof if(系统版本小于(@“9.0”))像这样你可以使用这不是正确的答案。我问我是否可以用预处理器宏来做。如果我的设备在iOS9上运行,我根本不想触发任何方法。#if#else预处理器宏有什么问题?我想你希望在每个版本中运行相同的代码?不,我不希望在iOS9中触发SupportedInterfaceOrientionsforWindow。你不能像这样使用预处理器宏,因为这是编译时功能。您需要一个运行时检查。为什么不为iOS 9.0及更高版本调用此委托方法?Maddy是对的-预处理器检查不会在运行时完成。所以你的版本要么有这个功能要么没有。你需要像特洛伊木马一样进行运行时检查。