检查iOS 7或更早版本的最佳方法? [英] Best Way to check for iOS 7 or earlier?

查看:115
本文介绍了检查iOS 7或更早版本的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据我正在运行的iOS版本重新配置一些UI,所以我需要一种检查iOS版本的好方法。暂时我这样做:

I need to reconfigure some UI based on the iOS version I am running against, so I need a good way of checking the iOS version. For the time being I am doing this:

if ([[[UIDevice currentDevice] systemVersion] isEqualToString: @"7.0"]) {
    //do stuff
}

我不想硬编码这些字符串比较并根据它做出决定。有没有更好的方法呢?

I'd prefer not to hard code these string comparisons and make decisions based on that. Are there any better ways of doing this?

推荐答案

我总是将这些保存在我的Constants.h文件中:

I always keep those in my Constants.h file:

#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)

虽然我总是喜欢上面的宏,但是为了完成接受的答案,这是苹果批准的方式:

Although I'll always prefer the above macros, for the completion of the accepted answer, here is the apple approved way:

if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {

    // do stuff for iOS 7 and newer

}
else {

    // do stuff for older versions than iOS 7
}

这篇关于检查iOS 7或更早版本的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆