获取Mac在Cocoa中的型号 [英] Getting Mac Model number in Cocoa
本文介绍了获取Mac在Cocoa中的型号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在做一个OS X应用程序,我需要得到的Mac模型,例如:
I'm making a OS X app where I need to get the Mac model, for example:
iMac11,3
MacBook3,1
等等。是否有任何类或函数来获取它?
And so on. Is there any class, or function to get it?
推荐答案
sysctl
:
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>
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);
printf("%s\n", model);
free(model);
}
这篇关于获取Mac在Cocoa中的型号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文