4

Is there a way to programmatically detect iOS version's build number, For example iOS version 9.0.2(13A452). I know how to detect iOS version eg: 9.0.2.

Is there any API to detect 13A452?

Thanks in advance.

user1150393
  • 139
  • 1
  • 15
  • Possible duplicate of [How to check iOS version?](http://stackoverflow.com/questions/3339722/how-to-check-ios-version) – Jason Nam Oct 19 '15 at 02:03
  • 1
    This question is specific to identifying build version not iOS version. I came across many posts on how to detect iOS version i.e, like 9.0.2. But couldn't find any information to obtain build version i.e, like 13A452. – user1150393 Oct 19 '15 at 02:09
  • I am curious to what kind of corner case forces you to check a specific build number of the OS. Apple usually recommends checking against available features (instead of against hard-coded OS version numbers), but I'm sure you must have your reasons. – Nicolas Miari Oct 19 '15 at 02:53
  • See this link for the solution. http://stackoverflow.com/a/5462277/5388157 – AliasCocoa Apr 27 '16 at 09:04
  • Solution in stackOver for your question ... http://stackoverflow.com/a/5462277/5388157 – AliasCocoa Apr 27 '16 at 09:09

2 Answers2

3

Figured I'd put the code up incase anyone needs it (works at run time), since it's slightly tricky to process!

MAKE SURE YOU #include <sys/sysctl.h>

//make sure you `#include <sys/sysctl.h>`

NSString *ctlKey = @"kern.osversion";

BOOL buildValueFound;
NSString *buildValue;

size_t size = 0;

if (sysctlbyname([ctlKey UTF8String], NULL, &size, NULL, 0) == -1) {

    buildValueFound = NO;

} else {

    char *machine = calloc( 1, size );

    sysctlbyname([ctlKey UTF8String], machine, &size, NULL, 0);
    NSString *ctlValue = [NSString stringWithCString:machine encoding:[NSString defaultCStringEncoding]];

    free(machine);

    buildValue = ctlValue;

    buildValueFound = YES;

}

if (buildValueFound) {
    NSLog(@"%@", buildValue);
} else {
    NSLog(@"No build value found");
}
Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
1

I have figured this out. Using KERN_OSVERSION on function sysctl returns iOS build number.

user1150393
  • 139
  • 1
  • 15