简体   繁体   English

UIDevice systemVersion有时包含操作系统名称

[英]UIDevice systemVersion sometimes contains the OS name

I have a problem with the method [[UIDevice currentDevice] systemVersion]. 我对方法[[UIDevice currentDevice] systemVersion]有问题。 We have a report with devices using the app, and sometimes we get a string like "iPhone OS 6.1.3". 我们有使用该应用程序的设备的报告,有时我们会收到类似“ iPhone OS 6.1.3”的字符串。

I don't know if there is another property for getting just the number (6.1.3) or if I have to implement a method to remove the first part. 我不知道是否还有另一个属性可以获取数字(6.1.3),或者我是否必须实现删除第一部分的方法。

Also I don't know exactly how many type of strings can I receive from several devices. 我也不知道我可以从几种设备接收多少种字符串。

Thanks in advance for your help, Regards 预先感谢您的帮助,问候

just do a regular expression to grab solely the number. 只需做一个正则表达式即可单独获取数字。

some simple expression like \\b[0-9].[0-9](.[0-9])?\\b or something like that. 一些简单的表达式,例如\\b[0-9].[0-9](.[0-9])?\\b或类似的表达式。

This can be applied through an NSRegularExpression . 这可以通过NSRegularExpression来应用。

Something like this 像这样

NSError *error;
NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:@"\b[0-9].[0-9](.[0-9])?\b" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *version = [[expression matchesInString:[[UIDevice currentDevice] systemVersion]] objectAtIndex:0];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM