我想使用以下代码,但仅适用于在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
但是,当我构建代码并在设备上运行时,该方法不会执行。我做错了什么?该应用程序具有最低iOS支持7.0,并且也可以在iOS9中运行(最新的xcode 7)
答案 0 :(得分:1)
您需要删除#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
和#endif
然后我认为这样做:
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version < 9.0f)
test()
答案 1 :(得分:1)
使用此&#34;系统版本控制预处理器宏&#34;用于检查系统版本
#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)