6

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

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

When I test this by running in my iPhone which is having iOS 8.0.2, this api returns me 8.000000 as the result but I need the exact iOS version which is 8.0.2

Any help in fixing this problem is appreciated in advance.

Splendor_iOS
  • 217
  • 1
  • 3
  • 10

5 Answers5

14

In iOS 8 and above, you can use:

[[NSProcessInfo processInfo] operatingSystemVersion]

If you want to check the availablity of particular API, then there is a better way than checking OS versions, as explained here.

Community
  • 1
  • 1
ZeMoon
  • 20,054
  • 5
  • 57
  • 98
7

you can get it with this, in NSString format:

[UIDevice currentDevice].systemVersion

NEW EDIT

PS

you changed your question... now my answer has no more sense... next time add new lines with an evident edit, to let everyone understand the thread of the question/answers, please

meronix
  • 6,175
  • 1
  • 23
  • 36
2

Objective 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 that:

if (SYSTEM_VERSION_LESS_THAN(@"10.0")){
   //your code here 
}
Stan
  • 1,513
  • 20
  • 27
1
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
dmaulikr
  • 458
  • 5
  • 20
  • Thank you for this code snippet, which may provide some immediate help. A proper explanation would [greatly improve](https://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) its educational value by showing why this is a good solution to the problem, and would make it more useful to future readers with similar, but not identical, questions. Please edit your answer to add explanation, and give an indication of what limitations and assumptions apply. – basvk Jul 04 '17 at 11:39
0

maybe not the more elegant solution ever but it definitely does the job, so you can try something like that 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'd be able convert to a more desirable format for your analytics.

holex
  • 23,961
  • 7
  • 62
  • 76