我想检查设备的iOS版本是否大于3.1.3 我尝试了以下方法:
[[UIDevice currentDevice].systemVersion floatValue]
但是不管用,我只想要一个:
if (version > 3.1.3) { }
我怎样才能做到这一点呢?
我想检查设备的iOS版本是否大于3.1.3 我尝试了以下方法:
[[UIDevice currentDevice].systemVersion floatValue]
但是不管用,我只想要一个:
if (version > 3.1.3) { }
我怎样才能做到这一点呢?
当前回答
仅用于检索OS版本字符串值:
[[UIDevice currentDevice] systemVersion]
其他回答
在主界面轻按“设置”>常规>关于。 设备的软件版本应该出现在这个屏幕上。 检查版本号是否大于3.1.3。
Try:
NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"3.1.3" options: NSNumericSearch];
if (order == NSOrderedSame || order == NSOrderedDescending) {
// OS version >= 3.1.3
} else {
// OS version < 3.1.3
}
有7.0或6.0.3这样的版本,所以我们可以简单地将版本转换为数字进行比较。如果版本类似于7.0,只需追加另一个”。0”,然后取它的数值。
int version;
NSString* iosVersion=[[UIDevice currentDevice] systemVersion];
NSArray* components=[iosVersion componentsSeparatedByString:@"."];
if ([components count]==2) {
iosVersion=[NSString stringWithFormat:@"%@.0",iosVersion];
}
iosVersion=[iosVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
version=[iosVersion integerValue];
为0
if (version==600) {
// Do something
}
为7.0
if (version==700) {
// Do something
}
开始Xcode 9,在Objective-C中:
if (@available(iOS 11, *)) {
// iOS 11 (or newer) ObjC code
} else {
// iOS 10 or older code
}
开始Xcode 7,在Swift中:
if #available(iOS 11, *) {
// iOS 11 (or newer) Swift code
} else {
// iOS 10 or older code
}
对于版本,您可以指定MAJOR、MINOR或PATCH(参见http://semver.org/的定义)。例子:
iOS 11和iOS 11.0是相同的最小版本 iOS 10, iOS 10.3, iOS 10.3.1是不同的最小版本
您可以为这些系统中的任何一个输入值:
iOS, macOS, watchOS, tvOS
来自我的一个豆荚的真实案例:
if #available(iOS 10.0, tvOS 10.0, *) {
// iOS 10+ and tvOS 10+ Swift code
} else {
// iOS 9 and tvOS 9 older code
}
文档
试试下面的代码:
NSString *versionString = [[UIDevice currentDevice] systemVersion];