The resources

Official lookup type list: support.apple.com/kb/index?q=…

Identify MacBook Pro models: support.apple.com/zh-cn/HT201… Identify MacBook models: support.apple.com/zh-cn/HT201… Identify MacBook Air models: support.apple.com/zh-cn/HT201… Identify your iMac model: support.apple.com/zh-cn/HT201… Identify Mac Pro models: support.apple.com/zh-cn/HT202…

, etc.

Mac version: en.wikipedia.org/wiki/Mac_Mi… en.wikipedia.org/wiki/IMac

Image from Internet

Obtain the Mac system version number:
NSString *versionString; // System version NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; versionString = [sv objectForKey:@"ProductVersion"];Copy the code
Obtain the string corresponding to the device model :(model identifier)
NSString *macDevTypeStr = @"Unknown Mac"; // Device model size_t len = 0; sysctlbyname("hw.model", NULL, &len, NULL, 0); if (len) { NSMutableData *data = [NSMutableData dataWithLength:len]; sysctlbyname("hw.model", [data mutableBytes], &len, NULL, 0); macDevTypeStr = [NSString stringWithUTF8String:[data bytes]]; }Copy the code

Write a category (NSString+SystemOrDeviceInfo) to implement both functions:

. “h” file:

#import <Foundation/ foundation. h> NS_ASSUME_NONNULL_BEGIN @interface NSString (SystemOrDeviceInfo) /** Obtain the device model @return Device model */ +(NSString *)getTheDeviceType; @return System version */ +(NSString *)getTheSystemVersion; @end NS_ASSUME_NONNULL_ENDCopy the code

“M” file:

#import "NSString+SystemOrDeviceInfo.h" #import <sys/sysctl.h> @implementation NSString (SystemOrDeviceInfo) +(NSString *)getTheSystemVersion { NSString *versionString; // System version NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; versionString = [sv objectForKey:@"ProductVersion"]; return versionString; } +(NSString *)getTheDeviceType { NSString *macDevTypeStr = @"Unknown Mac"; // Device model size_t len = 0; sysctlbyname("hw.model", NULL, &len, NULL, 0); if (len) { NSMutableData *data = [NSMutableData dataWithLength:len]; sysctlbyname("hw.model", [data mutableBytes], &len, NULL, 0); macDevTypeStr = [NSString stringWithUTF8String:[data bytes]]; } return macDevTypeStr; } @endCopy the code

Mac with Metal support:Support.apple.com/zh-cn/HT205…

Identify the MacBook: support.apple.com/zh-cn/HT201… Identify MacBook Air models: support.apple.com/zh-cn/HT201… Identify MacBook Pro models: support.apple.com/zh-cn/HT201… Identify Mac Mini models: support.apple.com/zh-cn/HT201… Identify the iMac: support.apple.com/zh-cn/HT201… Identify Mac Pro: support.apple.com/zh-cn/HT202…

The following devices with OS X El Capitan(10.11) or later support Metal!

MacBook: Model IDENTIFIER (device type) The value is “MacBook8,1” or later (2015) MacBookAir: Model identifier (device type) The value is “MacBookAir5,1” or later (2012) MacBook Pro: Model IDENTIFIER (Device type) The value is “MacBookPro9,1” or later (2012). Mac Mini: The value is “Macmini6,1” or later (2012). IMac: Model IDENTIFIER (Device type) The value is “iMac13,1” or later. (2012) iMacPro: Model Identifier (device type) The value contains “iMacPro” (all iMacPro models) MacPro: Model IDENTIFIER (Device type) The character string is “MacPro5,1” or later (2010).

Code for judging:

/** Support Metal or not */ NSString * devTypeStr = [NSString getTheDeviceType]; BOOL isSupportMetal = [self checkIsSupportTheMetalWithDevTypeStr:devTypeStr]; // SupportMetal or not NSLog(@" SupportMetal or not: %d\n",isSupportMetal);Copy the code

Method implementation:

/ * * note: Metal MacBook Model Identifier (device type) The value is "MacBook8,1" or higher (2015) MacBookAir Model identifier (device type) The value is "MacBookAir5,1" or higher (2012) MacBook Pro model IDENTIFIER (device type) The value is "MacBookPro9,1" or higher (2012) Mac Mini model identifier (device type) The value is "Macmini6,1" or higher (2012) iMac model identifier (device type) The value is "iMac13,1" or higher (2012) iMacPro model IDENTIFIER (device type) The value contains "iMacPro" (all iMacPro models) MacPro model identifier (device type) The value is "MacPro5,1" or higher (2010) */ @param devTypeStr Specifies the device type of the computer. @return Specifies whether the computer supports Metal */ -(BOOL)checkIsSupportTheMetalWithDevTypeStr:(NSString *)devTypeStr { BOOL isSupport = NO; //"MacBook8,1" above /"MacBookAir5,1" above /"MacBookPro9,1" above /"Macmini6,1" above /"iMac13,1" above/contains "iMacPro"/"MacPro5,1" above if ([devTypeStr containString:@"MacBook"] && (! [devTypeStr containString:@"MacBookAir"] && ! [devTypeStr containString:@"MacBookPro"])) {// Not MacBook Air and MacBookPro NSString * sub_CampareStr = [devTypeStr stringByReplacingOccurrencesOfString:@"MacBook" withString:@""]; If ([self biggerCompareTheDevTypeStr: sub_CampareStr withTheBaseStr: @ "8, 1"] = = YES) {/ / "MacBook8, 1" above (the current type > "8, 1") isSupport = YES; } } else if ([devTypeStr containString:@"MacBookAir"]) { NSString * sub_CampareStr = [devTypeStr stringByReplacingOccurrencesOfString:@"MacBookAir" withString:@""]; If ([self biggerCompareTheDevTypeStr: sub_CampareStr withTheBaseStr: @ "5, 1"] = = YES) {/ / "MacBookAir5, 1" above (the current type > "5, 1)" isSupport = YES; } } else if ([devTypeStr containString:@"MacBookPro"]) { NSString * sub_CampareStr = [devTypeStr stringByReplacingOccurrencesOfString:@"MacBookPro" withString:@""]; If ([self biggerCompareTheDevTypeStr: sub_CampareStr withTheBaseStr: @ "9, 1"] = = YES) {/ / "MacBookPro9, 1" above (the current type > "9, 1)" isSupport = YES; } } else if ([devTypeStr containString:@"Macmini"]) { NSString * sub_CampareStr = [devTypeStr stringByReplacingOccurrencesOfString:@"Macmini" withString:@""]; If ([self biggerCompareTheDevTypeStr: sub_CampareStr withTheBaseStr: @ "6, 1"] = = YES) {/ / "Macmini6, 1" above (the current type > "6, 1)" isSupport = YES; } } else if ([devTypeStr containString:@"iMac"] && (! [devTypeStr containString:@"iMacPro"])) {// Not iMacPro NSString * sub_CampareStr = [devTypeStr stringByReplacingOccurrencesOfString:@"iMac" withString:@""]; If ([self biggerCompareTheDevTypeStr: sub_CampareStr withTheBaseStr: @ "13, 1"] = = YES) {/ / "iMac13, 1" above (the current type > "13, 1") isSupport = YES; }} else if ([devTypeStr :@"iMacPro"]) {// contains "iMacPro" isSupport = YES; } else if ([devTypeStr containString:@"MacPro"] && ! [devTypeStr containString:@"iMacPro"]) { NSString * sub_CampareStr = [devTypeStr stringByReplacingOccurrencesOfString:@"MacPro" withString:@""]; If ([self biggerCompareTheDevTypeStr: sub_CampareStr withTheBaseStr: @ "5, 1"] = = YES) {/ / "MacPro5, 1" above (the current type > "5, 1)" isSupport = YES; } } NSString * sys_Ver_Str = [NSString getTheSystemVersion]; If ([self compareVersionStr:sys_Ver_Str andBaseVesrionStr:@"10.11"] == YES) {OS X El Capitan (10.11)} else { OS X El Capitan (10.11) isSupport = NO; } //NSLog(@"isSupport:%d\n",isSupport); return isSupport; } // MAC version size comparison -(BOOL)compareVersionStr:(NSString *)verStr andBaseVesrionStr:(NSString *)baseVerStr {BOOL isBiggerThanBaseVer = NO; NSArray * base_VerStr_Arr = [baseVerStr componentsSeparatedByString:@"."]; NSArray * comp_VerStr_Arr = [verStr componentsSeparatedByString:@"."]; for (int i = 0; i < base_VerStr_Arr.count; i ++) { int comp_Ver_int = [comp_VerStr_Arr[i] intValue]; int base_Ver_int = [base_VerStr_Arr[i] intValue]; If (comp_Ver_int < base_Ver_int) {// If (comp_Ver_int < base_Ver_int) {isBiggerThanBaseVer = NO; break; } if (I == base_verstr_arr.count-1) {// The last bit is still greater than the base version number isBiggerThanBaseVer = YES; } } return isBiggerThanBaseVer; } /** Model version Model size comparison @param devTypeStr Current device model @param baseStr Basic device model @return Whether current device model >= Basic device model */ -(BOOL)biggerCompareTheDevTypeStr:(NSString *)devTypeStr withTheBaseStr:(NSString *)baseStr { BOOL isBiggerThanBaseVer =  NO; NSArray * comp_DevTypeStr_Arr = [devTypeStr componentsSeparatedByString:@","]; int comp_Ver_int_0 = [comp_DevTypeStr_Arr[0] intValue]; int comp_Ver_int_1 = [comp_DevTypeStr_Arr[1] intValue]; NSArray * base_DevTypeStr_Arr = [baseStr componentsSeparatedByString:@","]; int base_Ver_int_0 = [base_DevTypeStr_Arr[0] intValue]; int base_Ver_int_1 = [base_DevTypeStr_Arr[1] intValue]; If (comp_Ver_int_0 >= base_Ver_int_0) {if (comp_Ver_int_1 >= base_Ver_int_1) { } } return isBiggerThanBaseVer; }Copy the code

supportRetina Display:

When using 4K display, also meet the Retina support standard! (Add corresponding judgments to the code)

Identify the MacBook: support.apple.com/zh-cn/HT201… Identify MacBook Air models: support.apple.com/zh-cn/HT201… Identify MacBook Pro models: support.apple.com/zh-cn/HT201… Identify Mac Mini models: support.apple.com/zh-cn/HT201… Identify the iMac: support.apple.com/zh-cn/HT201…

The following Mac devices support Retina!

MacBook: Model IDENTIFIER (device type) The value is “MacBook8,1” or later (2015). MacBookAir: Model identifier (device type) The value is “MacBookAir8,1” or later (2018). MacBook Pro: Model IDENTIFIER (Device type) The value is “MacBookPro10,1” or later (2012) iMac: Model IDENTIFIER (device type) The value is “iMac15,1” or later (2014) (“iMac16,1″(2015)\”iMac18,1″(2017) exception). Model IDENTIFIER (Device type) The value contains “iMacPro” (all models of iMacPro).

Code for judging:

/** Retina support or not */ NSString * devTypeStr = [NSString getTheDeviceType]; BOOL isSupportRetina = [self checkIsSupportRitinaWithDevTypeStr:devTypeStr]; // support Retina or not NSLog(@" support Retina or not: %d\n",isSupportRetina);Copy the code

Implementation of the method :(note – Mac mini uses 4K display, also meet the Retina support standard! Need to add the corresponding judgment!

/ * * note: The following devices and above support Retina MacBook Model Identifier (device type) The value is "MacBook8,1" or higher (2015) MacBookAir Model identifier (device type) The value is "MacBookAir8,1" or higher (2018) MacBook Pro model IDENTIFIER (device type) The value is "MacBookPro10,1" or higher (2012) iMac model identifier (device type) The value is "iMac15,1" or higher (2014) except iMac16,1(2015) iMac18, and 1(2017) IMac Pro model Identifier (device type) The character string contains "iMacPro" (all iMacPro models) 4K display also meets the Retina support standard! */ /** Check whether the computer supports Ritina @param devTypeStr Device type string @return whether the computer supports Ritina */ -(BOOL)checkIsSupportRitinaWithDevTypeStr:(NSString *)devTypeStr { BOOL isSupport = NO; If ([self isRetinaDisplayOfScreen]) {// is 4K display isSupport = YES; return isSupport; } //"MacBook8,1" above /"MacBookAir8,1" above /"MacBookPro10,1 above /"iMac15,1 above (16,1\18,1 exception)/ contains "iMacPro" if ([devTypeStr) containString:@"MacBook"] && (! [devTypeStr containString:@"MacBookAir"] && ! [devTypeStr containString:@"MacBookPro"])) {// Not MacBook Air and MacBookPro NSString * sub_CampareStr = [devTypeStr stringByReplacingOccurrencesOfString:@"MacBook" withString:@""]; If ([self biggerCompareTheDevTypeStr: sub_CampareStr withTheBaseStr: @ "8, 1"] = = YES) {/ / "MacBook8, 1" above (the current type > "8, 1") isSupport = YES; } } else if ([devTypeStr containString:@"MacBookAir"]) { NSString * sub_CampareStr = [devTypeStr stringByReplacingOccurrencesOfString:@"MacBookAir" withString:@""]; If ([self biggerCompareTheDevTypeStr: sub_CampareStr withTheBaseStr: @ "8, 1"] = = YES) {/ / "MacBookAir8, 1" above (the current type > "8, 1") isSupport = YES; } } else if ([devTypeStr containString:@"MacBookPro"]) { NSString * sub_CampareStr = [devTypeStr stringByReplacingOccurrencesOfString:@"MacBookPro" withString:@""]; If ([self biggerCompareTheDevTypeStr: sub_CampareStr withTheBaseStr: @ "10, 1"] = = YES) {/ / above "MacBookPro10, 1" (the current type > "10, 1") isSupport = YES; } } else if ([devTypeStr containString:@"iMac"] && (! [devTypeStr containString:@"iMacPro"])) {// Not iMacPro NSString * sub_CampareStr = [devTypeStr stringByReplacingOccurrencesOfString:@"iMac" withString:@""]; If ([self biggerCompareTheDevTypeStr: sub_CampareStr withTheBaseStr: @ "15, 1"] = = YES) {/ / "iMac15, 1" above (the current type > "15, 1") isSupport = YES; If ([sub_CampareStr isEqualToString: @ "16, 1]" | | [sub_CampareStr isEqualToString: @ "18, 1]) {/ / isSupport = (16 18, 1, 1 \ exception) NO; }}} else if ([devTypeStr containString:@"iMacPro"]) {// contain "iMacPro" isSupport = YES; } return isSupport; } // Is a 4K display - meet the Retina support standard! -(BOOL)isRetinaDisplayOfScreen { NSSize deviceResolution = NSZeroSize; deviceResolution = [self deviceResolutionOfScreen:[NSScreen mainScreen]]; if (NSEqualSizes(NSZeroSize, deviceResolution)) { return NO; } the if (deviceResolution width > = 144 | | deviceResolution. Height > = 144) {/ / 144 hz refresh rate????? return YES; } else { return NO; }} - (NSSize) deviceResolutionOfScreen: (aScreen NSScreen *) {/ / for the current display screen information if (aScreen = = nil) {return NSZeroSize; } NSDictionary * dictionary = [aScreen deviceDescription]; NSSize deviceResolution = NSZeroSize; deviceResolution = [[dictionary objectForKey:(id)NSDeviceResolution] sizeValue]; return deviceResolution; }Copy the code

Actual use:

Retina display, when displaying effects (graphics/video) – Retina display is 4 times the size of non-Retina display (twice the length and width!) Our company’s product is a video player App, so the width and height of the rendering screen are multiplied by 2 when setting and using it.

HiDPI is enabled by default in retina products! HiDPI is a doubling of the pixels in each dimension (width, height).

The pixel size of the non-Retina screen is four times that of the Retina screen, resulting ina larger area for displaying the same content.


Using the instance

Obtain the system version number:

NSString *versionString; // System version NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; versionString = [sv objectForKey:@"ProductVersion"]; NSLog (@ versionString: "% @", versionString);Copy the code

Print:

VersionString: 10.13.6Copy the code

Plist file path:


Device model:

NSString *macDevType = @"Unknown Mac"; // Device model size_t len = 0; sysctlbyname("hw.model", NULL, &len, NULL, 0); if (len) { NSMutableData *data = [NSMutableData dataWithLength:len]; sysctlbyname("hw.model", [data mutableBytes], &len, NULL, 0); macDevType = [NSString stringWithUTF8String:[data bytes]]; } NSLog (@ "macDeviceType: % @," macDevType);Copy the code

Print:

MacDeviceType: Macmini7, 1Copy the code

goyohol’s essay