我需要根据我运行的 iOS 版本重新配置一些 UI,因此我需要一种检查 iOS 版本的好方法。目前我正在这样做:
if ([[[UIDevice currentDevice] systemVersion] isEqualToString: @"7.0"]) {
//do stuff
}
我不想对这些字符串比较进行硬编码并据此做出决定。有更好的方法吗?
我总是将它们保存在 Constants.h 文件中:
#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)
#define IS_OS_5_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0)
#define IS_OS_6_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
#define IS_OS_7_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
#define IS_OS_9_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0)
虽然我总是更喜欢上面的宏,但为了完成接受的答案,这是苹果批准的方式:
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
// do stuff for iOS 7 and newer
}
else {
// do stuff for older versions than iOS 7
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)