我需要重新配置基于我运行的iOS版本的一些用户界面,所以我需要一个检查iOS版本的好方法。目前我这样做:检查iOS 7或更低版本的最佳方法?
if ([[[UIDevice currentDevice] systemVersion] isEqualToString: @"7.0"]) {
//do stuff
}
我宁愿不硬编码这些字符串比较,并根据它作出决定。有没有更好的方法来做到这一点?
我需要重新配置基于我运行的iOS版本的一些用户界面,所以我需要一个检查iOS版本的好方法。目前我这样做:检查iOS 7或更低版本的最佳方法?
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
}
+1我以前从未见过这个。 –
对于它的价值,这是苹果在采用iOS 7会议的2013 Tech Talk上的建议 - 尽管他们在调用“floor()”时包装了“NSFoundationVersionNumber”。 –
会不会有一个6.2.x会使检查无效? –
如果iOS 7.1出来的话,将会中断。但是你在正确的轨道上。如果你关心的是iOS7,一般来说,将字符串分开并仅比较主要版本。 – Krumelur
有你看着[1] [1] [这个答案?]:http://stackoverflow.com/questions/12561599/how-to-check-ios-version-is-ios-6/12561661#12561661 – shrimp
这看起来最稳定 – Huang