在iOS上,有一个UIDevice类,它可以让你获得有关设备型号,操作系统等的大量信息......
我在Mac上寻找相同的东西。我知道从命令行调用system_profiler
,但即使是mini
设置也需要几秒钟才能获得任何信息。
我对从Mac应用程序中获取机器类型(Macbook Air,Mac Mini等),操作系统版本以及其他快速机器详细信息的快速方法感兴趣。详细信息将用作从应用程序内发送的支持电子邮件的页脚。有没有相当于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];
free(model);
return model_ns;
}
return @"Just an Apple Computer"; //in case model name can't be read
}
Swift版本(只需交换hw.model
for hw.machine
)就在这里https://stackoverflow.com/a/25467259/308315
是否打电话给system_profiler SPHardwareDataType
可以满足您的需求?它返回非常快并返回一些基本的硬件信息。您可以通过调用system_profiler -listDataTypes
找到您可以请求的其他数据。我认为你的谜题的另一部分将是system_profiler SPSoftwareDataType
。
没有内置设备类,如在iOS中。
您需要使用Gestalt Manager来调查操作环境。