How to get the correct version of iOS programmatically?

I want to get the current version of the os user device for some analysis in the backend. I am trying to get it as below

[[[UIDevice currentDevice] systemVersion] floatValue]; **//not returning the minor version number** 

When I test this while working on my iPhone that has iOS 8.0.2, this api returns me 8.000000 as a result, but I need the exact version of iOS that is 8.0.2

Any help in resolving this issue is evaluated in advance.

+6
source share
5 answers

In iOS 8 and above, you can use:

 [[NSProcessInfo processInfo] operatingSystemVersion] 

If you want to check the availability of a specific API, then there is a better way than checking OS versions, as described here .

+12
source

you can get it using this in NSString format:

 [UIDevice currentDevice].systemVersion 

NEW EDIT

PS

you changed your question ... now my answer no longer makes sense ... next time add new lines with obvious edit so that everyone can understand the flow of question / answers, please

+7
source
 NSString *osVersion = [[UIDevice currentDevice] systemVersion]; 
+1
source

Goal c

 // define macro #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) 

then use like this:

 if (SYSTEM_VERSION_LESS_THAN(@"10.0")){ //your code here } 
0
source

maybe not a more elegant solution, but it definitely does the job, so you can try something like this in ObjC:

 - (NumVersion)systemVersion { NSArray *_separated = [[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."]; NumVersion _version = { 0, 0, 0, 0 }; if (_separated.count > 3) _version.stage = [[_separated objectAtIndex:3] integerValue]; if (_separated.count > 2) _version.nonRelRev = [[_separated objectAtIndex:2] integerValue]; if (_separated.count > 1) _version.minorAndBugRev = [[_separated objectAtIndex:1] integerValue]; if (_separated.count > 0) _version.majorRev = [[_separated objectAtIndex:0] integerValue]; return _version; } 

then

 NumVersion version = [self systemVersion]; NSLog(@"%d, %d, %d, %d", version.majorRev, version.minorAndBugRev, version.nonRelRev, version.stage); 

will print (in my case at the very moment):

 11, 0, 2, 0 

what you could convert to a more desirable format for your analytics.

0
source

Source: https://habr.com/ru/post/984438/


All Articles