iOS10中系统版本的判断

在iOS10中,当需要判断系统版本号的时候,不能再用以下这种方法了:

#define isiOS10 ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue]>=10)

这是为什么呢? 因为在iOS10中,substringToIndex:1 iOS 10会被检测成iOS 1,所以此结果永远都是返回NO。

你应该使用下面这些方法:

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

Swift中可以这样写:

if #ava

if #available(iOS 10.0, *) {

//iOS 10以上系统

} else {

//iOS 10之前的系统

}

你可能感兴趣的:(iOS10中系统版本的判断)