Mac获取系统版本、机型

时间:2025-03-27 07:34:30
// 获取系统版本

NSString *versionString;
NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/"];
versionString = [sv objectForKey:@"ProductVersion"];
NSLog(@"%@", versionString);
NSString* major = @"";
NSString* minjor = @"";
NSArray* majminor = [versionString componentsSeparatedByString:@"."];
LOG_INFO("Verify_CORE_ML 26.3");
major = [majminor objectAtIndex:0];
LOG_INFO("Verify_CORE_ML 26.4");
minjor = [majminor objectAtIndex:1];
// 获取Mac笔记本型号:Model Identifier
// 官方型号列表:/en-us/HT201300
// 命令行查看:system_profiler SPHardwareDataType
size_t len = 0;
sysctlbyname("", NULL, &len, NULL, 0);
if (len) {
  char *model = (char*)malloc(len*sizeof(char));
  sysctlbyname("", model, &len, NULL, 0);
  printf("%s\n", model);// 我的机器输出:MacBookPro16,1
  free(model);
}