如何以编程方式获取iOS的字母数字版本字符串 [英] How to programmatically get iOS's alphanumeric version string

查看:145
本文介绍了如何以编程方式获取iOS的字母数字版本字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用漂亮的 PLCrashReport 框架向我的服务器发送崩溃来自我用户的iOS设备的报告。

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

但是,为了表示崩溃报告, symbolicatecrash 实用程序会请求iPhone OS版本号,我有ipsw的字母数字版本,格式为:

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)

我知道我可以通过 [[UIDevice currentDevice] systemVersion]获取iOS的数字版本,但我怎样才能得到另一个呢?

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.

推荐答案

不确定为什么其他人说这是不可能的,因为它使用 sysctl 函数。

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;   
}

这篇关于如何以编程方式获取iOS的字母数字版本字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆