[英]Best Way to check for iOS 7 or earlier? [duplicate]
这个问题在这里已有答案:
我需要根据我运行的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
}
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
// do stuff for iOS 7 and newer
}
else {
// do stuff for older versions than iOS 7
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.