Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically get iOS's alphanumeric version string

I've been working with the nice PLCrashReport framework to send to my server the crash reports from my user's iOS devices.

However, to symbolicate the crash report, the symbolicatecrash utility requests that along with the iPhone OS version number, I have the ipsw's alphanumeric version, in the form of:

OS Version:      iPhone OS 4.0.1 (8A293)

I know that I can get the iOS's numeric version by [[UIDevice currentDevice] systemVersion], but how can I get the other one?

I can't find a way, and I've searched everywhere I could imagine.

like image 761
Claudio Martins Avatar asked Jan 31 '11 23:01

Claudio Martins


4 Answers

Not sure why others are saying that this is not possible because it is using the sysctl function.

#import <sys/sysctl.h>    

- (NSString *)osVersionBuild {
    int mib[2] = {CTL_KERN, KERN_OSVERSION};
    u_int namelen = sizeof(mib) / sizeof(mib[0]);
    size_t bufferSize = 0;

    NSString *osBuildVersion = nil;

    // Get the size for the buffer
    sysctl(mib, namelen, NULL, &bufferSize, NULL, 0);

    u_char buildBuffer[bufferSize];
    int result = sysctl(mib, namelen, buildBuffer, &bufferSize, NULL, 0);

    if (result >= 0) {
        osBuildVersion = [[[NSString alloc] initWithBytes:buildBuffer length:bufferSize encoding:NSUTF8StringEncoding] autorelease]; 
    }

    return osBuildVersion;   
}
like image 188
Dylan Copeland Avatar answered Oct 24 '22 06:10

Dylan Copeland


Why don´t you try this?

NSString *os_version = [[UIDevice currentDevice] systemVersion];

NSLog(@"%@", os_version);

if([[NSNumber numberWithChar:[os_version characterAtIndex:0]] intValue]>=4) {
    // ...
}
like image 43
Ziggy Avatar answered Oct 24 '22 07:10

Ziggy


I've reached here looking for an answer to how to do this in Swift and, after some test and error, just found that you can write this, at least in Xcode 9:

print(ProcessInfo().operatingSystemVersionString)

And the output I get in simulator is:

Version 11.0 (Build 15A5278f)

And in a real device:

Version 10.3.2 (Build 14F89)

Hope it helps.

like image 4
widemos Avatar answered Oct 24 '22 07:10

widemos


I had problems uploading Dylan's string to a PHP web server, the URL connection would just hang, so I modified the code as follows to fix it:

#include <sys/sysctl.h>

    - (NSString *)osVersionBuild {
        int mib[2] = {CTL_KERN, KERN_OSVERSION};
        size_t size = 0;

        // Get the size for the buffer
        sysctl(mib, 2, NULL, &size, NULL, 0);

        char *answer = malloc(size);
        int result = sysctl(mib, 2, answer, &size, NULL, 0);

        NSString *results = [NSString stringWithCString:answer encoding: NSUTF8StringEncoding];
        free(answer);
        return results;  
    }
like image 3
malhal Avatar answered Oct 24 '22 08:10

malhal