请教一个[[UIDevice currentDevice] systemVersion]方法问题,有时应用会发送一个关于设备版本的报告,比如"iPhone OS 6.1.3"
。
不知道有没有属性可以实现只获取数字 (6.1.3),还是要用方法实现删除前面的部分。
同时我还想知道多个设备可以获取多少种类型的字符串。
请教一个[[UIDevice currentDevice] systemVersion]方法问题,有时应用会发送一个关于设备版本的报告,比如"iPhone OS 6.1.3"
。
不知道有没有属性可以实现只获取数字 (6.1.3),还是要用方法实现删除前面的部分。
同时我还想知道多个设备可以获取多少种类型的字符串。
[[UIDevice currentDevice] systemVersion]方法返回当前设备的系统版本,它是一个字符串类型。返回的字符串格式为"iPhone OS X.X.X"(其中X.X.X是版本号)。如果你只需要版本号部分的话,可以使用字符串的截取方法来删除前面的部分。例如:
NSString *version = [[UIDevice currentDevice] systemVersion];
NSString *shortVersion = [version substringFromIndex:10];
或者用正则表达式提取
NSString *version = [[UIDevice currentDevice] systemVersion];
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9.]+" options:0 error:NULL];
NSTextCheckingResult *match = [regex firstMatchInString:version options:0 range:NSMakeRange(0, version.length)];
NSString *shortVersion = [version substringWithRange:match.range];
不同设备可以获取到不同类型的系统版本字符串,因为不同设备有着不同的系统版本。
例如 iPhone , iPad, Apple TV, HomePod 就有不同的版本
比如 iPhone 设备可以获取的系统版本可能为 "iOS X.X" 、"iPhone OS X.X" 之类的。