IOS 中获取系统版本,比较简单([[UIDevice currentDevice] systemVersion]);
看到网络上很多转化系统字符串到float 的方法,都是使用 [[[UIDevice currentDevice] systemVersion] floatValue];
但是这个方法我遇到一个问题,就是如果系统版本是7.1.1 的时候,转化生成的float 有问题,我debug 生成的数据为7.0899999999999。导致出现了问题,
后来为了解决这个问题,我自己写了一个方法。
+ (CGFloat )systemVersion{
NSString *sVersion = [[UIDevice currentDevice] systemVersion];
NSRange fRange = [sVersion rangeOfString:@"."];
CGFloat version = 0.0f;
if(fRange.location != NSNotFound){
sVersion = [sVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
NSMutableString *mVersion = [NSMutableString stringWithString:sVersion];
[mVersion insertString:@"." atIndex:fRange.location];
version = [mVersion floatValue];
}else {
// 版本应该有问题(由于ios 的版本 是7.0.1,没有发现出现过没有小数点的情况)
version = [sVersion floatValue];
}
return version;
}