只獲取了2017后的機(jī)型
- (NSString *)getDeviceModel {
NSString *result = @"";
size_t size = 0;
sysctlbyname("hw.model", NULL, &size, NULL, 0);
if (size != 0) {
char machine[size];
sysctlbyname("hw.model", machine, &size, NULL, 0);
result = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
}
return macDeviceModel(result);
}
- (NSString *)macDeviceModel:(NSString *)model {
NSString *deviceModel = model;
if ([deviceModel isEqualToString:@"Macmini9,1"]) {
return @"Mac mini (M1, 2020)";
} else if ([deviceModel isEqualToString:@"iMac21,1"] || [deviceModel isEqualToString:@"iMac21,2"]) {
return @"iMac (24-inch, M1, 2021)";
}
else if ([deviceModel isEqualToString:@"Mac13,1"] || [deviceModel isEqualToString:@"Mac13,2"]) {
return @"Mac Studio";
}
else if ([deviceModel isEqualToString:@"Mac14,3"] || [deviceModel isEqualToString:@"Mac14,12"]) {
return @"Mac mini (2023)";
}
else if ([deviceModel isEqualToString:@"Mac14,8"]) {
return @"Mac Pro (2023)";
}
else if ([deviceModel isEqualToString:@"Mac14,13"] || [deviceModel isEqualToString:@"Mac14,14"]) {
return @"Mac Studio (2023)";
}
else if ([deviceModel isEqualToString:@"Mac15,4"] || [deviceModel isEqualToString:@"Mac15,5"]) {
return @"iMac (24-inch, 2023)";
}
else if ([deviceModel isEqualToString:@"MacBookAir10,1"]) {
return @"MacBook Air (M1, 2020)";
}
else if ([deviceModel isEqualToString:@"MacBookPro17,1"]) {
return @"MacBook Pro (13-inch, M1, 2020)";
}
else if ([deviceModel isEqualToString:@"MacBookPro18,3"] || [deviceModel isEqualToString:@"MacBookPro18,4"]) {
return @"MacBook Pro (14-inch, 2021)";
}
else if ([deviceModel isEqualToString:@"MacBookPro18,1"] || [deviceModel isEqualToString:@"MacBookPro18,2"]) {
return @"MacBook Pro (16-inch, 2021)";
}
else if ([deviceModel isEqualToString:@"Mac14,2"]) {
return @"MacBook Air (M2, 2022)";
}
else if ([deviceModel isEqualToString:@"Mac14,7"]) {
return @"MacBook Pro (13-inch, M2, 2022)";
}
else if ([deviceModel isEqualToString:@"Mac14,5"] || [deviceModel isEqualToString:@"Mac14,9"]) {
return @"MacBook Pro (14-inch, 2023)";
}
else if ([deviceModel isEqualToString:@"Mac14,6"] || [deviceModel isEqualToString:@"Mac14,10"]) {
return @"MacBook Pro (16-inch, 2023)";
}
else if ([deviceModel isEqualToString:@"Mac14,8"]) {
return @"MacBook Air (15-inch, M2, 2023)";
}
else if ([deviceModel isEqualToString:@"Mac15,3"] || [deviceModel isEqualToString:@"Mac15,6"] || [deviceModel isEqualToString:@"Mac15,8"] || [deviceModel isEqualToString:@"Mac15,10"]) {
return @"MacBook Pro (14-inch, Nov 2023)";
}
else if ([deviceModel isEqualToString:@"Mac15,7"] || [deviceModel isEqualToString:@"Mac15,9"] || [deviceModel isEqualToString:@"Mac15,11"]) {
return @"MacBook Pro (16-inch, Nov 2023)";
}
else if ([deviceModel isEqualToString:@"Mac15,12"]) {
return @"MacBook Air (13-inch, M3, 2024)";
}
else if ([deviceModel isEqualToString:@"Mac15,13"]) {
return @"MacBook Air (15-inch, M3, 2024)";
}
else if ([deviceModel isEqualToString:@"iMac18,1"]) {
return @"iMac (Retina 4K, 21.5-inch, 2017)";
}
else if ([deviceModel isEqualToString:@"iMac18,2"]) {
return @"iMac (Retina 4K, 21.5-inch, 2017)";
}
else if ([deviceModel isEqualToString:@"iMac18,3"]) {
return @"iMac (Retina 5K, 27-inch, 2017)";
}
else if ([deviceModel isEqualToString:@"iMacPro1,1"]) {
return @"iMac Pro (2017)";
}
else if ([deviceModel isEqualToString:@"iMac19,1"]) {
return @"iMac (Retina 5K, 27-inch, 2019)";
}
else if ([deviceModel isEqualToString:@"iMac19,2"]) {
return @"iMac (Retina 4K, 21.5-inch, 2019)";
}
else if ([deviceModel isEqualToString:@"iMac20,1"] || [deviceModel isEqualToString:@"iMac20,2"]) {
return @"iMac (Retina 5K, 27-inch, 2020)";
}
else if ([deviceModel isEqualToString:@"MacBookPro14,1"] || [deviceModel isEqualToString:@"MacBookPro14,2"] || [deviceModel isEqualToString:@"MacBookPro14,3"]) {
return @"MacBook Pro 2017";
}
else if ([deviceModel isEqualToString:@"MacBookPro15,1"] || [deviceModel isEqualToString:@"MacBookPro15,2"] || [deviceModel isEqualToString:@"MacBookPro15,3"]) {
return @"MacBook Pro 2018";
}
else if ([deviceModel isEqualToString:@"MacBookPro15,4"]) {
return @"MacBook Pro 2019 (Butterfly Keyboard)";
}
else if ([deviceModel isEqualToString:@"MacBookPro16,1"] || [deviceModel isEqualToString:@"MacBookPro16,4"]) {
return @"MacBook Pro 2019 (Magic Keyboard)";
}
else if ([deviceModel isEqualToString:@"MacBookPro16,2"] || [deviceModel isEqualToString:@"MacBookPro16,3"]) {
return @"MacBook Pro 2020";
}
else if ([deviceModel isEqualToString:@"MacBookAir7,2"]) {
return @"MacBook Air 2017";
}
else if ([deviceModel isEqualToString:@"MacBookAir8,1"]) {
return @"MacBook Air 2018";
}
else if ([deviceModel isEqualToString:@"MacBookAir8,2"]) {
return @"MacBook Air 2019";
}
else if ([deviceModel isEqualToString:@"MacBookAir9,1"]) {
return @"MacBook Air 2020";
}
else if ([deviceModel isEqualToString:@"Macmini7,1"]) {
return @"Mac mini (Late 2014)";
}
else if ([deviceModel isEqualToString:@"Macmini8,1"]) {
return @"Mac mini 2018";
}
else if ([deviceModel isEqualToString:@"MacPro7,1"]) {
return @"Mac Pro 2019";
}
return @"Mac";
}