简体   繁体   中英

UIDevice systemVersion sometimes contains the OS name

I have a problem with the method [[UIDevice currentDevice] systemVersion]. We have a report with devices using the app, and sometimes we get a string like "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.

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.

This can be applied through an 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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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