如何以编程方式区分MacBook和Mac台式机? [英] How to distinguish MacBook and Mac desktops programmatically?
本文介绍了如何以编程方式区分MacBook和Mac台式机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用应区分MacBook和Mac台式机(iMac/Mac Pro)的Mac应用.
I'm working on a Mac app that should distinguish MacBook and Mac desktops (iMac/Mac Pro).
我想我可以用型号完成它.那我怎么得到型号呢?哪个字母表示它是笔记本电脑或台式机?还是还有其他更简便或更完善的方法?
I think I can get it done with model number. Then how I can get the model number? And which letter indicates it's a notebook or desktop? Or is there any other easier or better way?
推荐答案
您可以使用此小程序. NSLog
输出以对其进行测试.
You can use this little program. NSLog
the output to test it.
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>
+ (NSString *)machineModel
{
size_t length = 0;
sysctlbyname("hw.model", NULL, &length, NULL, 0);
if (length) {
char *m = malloc(length * sizeof(char));
sysctlbyname("hw.model", m, &length, NULL, 0);
NSString *model = [NSString stringWithUTF8String:m];
free(m);
return model;
}
return @"Unknown model";
}
它将提供与在终端上输入sysctl hw.model
相同的输出.
It will provide the same output as entering sysctl hw.model
on the terminal.
这篇关于如何以编程方式区分MacBook和Mac台式机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文