我正在开发一款应该区分MacBook和Mac台式机的Mac应用程序(iMac/Mac Pro).
我想我可以用型号来完成它.那我怎么得到型号?哪个字母表明它是笔记本电脑或台式机?或者还有其他更简单或更好的方法吗?
你可以使用这个小程序.NSLog输出来测试它.
#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";
}
Run Code Online (Sandbox Code Playgroud)
它将提供与sysctl hw.model在终端上输入相同的输出.
| 归档时间: |
|
| 查看次数: |
736 次 |
| 最近记录: |