通过Cocoa API获取计算机类型和其他硬件详细信息 [英] Getting the Machine Type and other Hardware details through Cocoa API

查看:325
本文介绍了通过Cocoa API获取计算机类型和其他硬件详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS上,有一个 UIDevice 类它可以让你得到吨的关于设备型号,操作系统等的好信息...



我在Mac上寻找等效的东西。我知道从命令行调用 system_profiler ,但即使 mini 设置需要几秒钟来获取任何信息。 / p>

我有兴趣快速获取机器类型(Macbook Air,Mac Mini等),操作系统版本和其他快速机器细节从Mac应用程序。细节将被用作支持从应用程序内发送的电子邮件的页脚。是否有任何等效的UIDevice,或另一种快速方式获得一些信息,可以帮助描述用户的机器?

解决方案

  #include< stdlib.h> 
#include< stdio.h>
#include< sys / types.h>
#include< sys / sysctl.h>

+(NSString *)machineModel
{
size_t len = 0;
sysctlbyname(hw.model,NULL,& len,NULL,0);

if(len)
{
char * model = malloc(len * sizeof(char));
sysctlbyname(hw.model,model,& len,NULL,0);
NSString * model_ns = [NSString stringWithUTF8String:model];
免费(模型);
return model_ns;
}

return @Just a Apple Computer; // incase模型名称无法读取
}


On iOS, there is a UIDevice class which lets you get tons of great info about the device model, operating system etc…

I am looking for something equivalent on the Mac. I know about calling system_profiler from the command line, but even the mini setting takes several seconds to get any info.

I am interested in fast ways to get the machine type (Macbook Air, Mac Mini, etc…), OS version, and other quick machine details from within a Mac App. The details are going o be used as a footer on support emails sent from within the app. Is there any equivalent to UIDevice, or another fast way to get some info that could help describe a user's machine?

解决方案

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>

+(NSString *) machineModel
{
    size_t len = 0;
    sysctlbyname("hw.model", NULL, &len, NULL, 0);

    if (len)
    {
        char *model = malloc(len*sizeof(char));
        sysctlbyname("hw.model", model, &len, NULL, 0);
        NSString *model_ns = [NSString stringWithUTF8String:model];
        free(model);
        return model_ns;
    }

    return @"Just an Apple Computer"; //incase model name can't be read
}

这篇关于通过Cocoa API获取计算机类型和其他硬件详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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