Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iPhoneXS / iPhone XS Max / iPhone XR / iPad 6 support #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 38 additions & 32 deletions SDVersion/SDiOSVersion/SDiOSVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,48 @@ typedef NS_ENUM(NSInteger, DeviceVersion){
UnknownDevice = 0,
Simulator = 1,

iPhone4 = 3,
iPhone4S = 4,
iPhone5 = 5,
iPhone5C = 6,
iPhone5S = 7,
iPhone6 = 8,
iPhone6Plus = 9,
iPhone6S = 10,
iPhone6SPlus = 11,
iPhone4 = 2,
iPhone4S = 3,
iPhone5 = 4,
iPhone5C = 5,
iPhone5S = 6,
iPhone6 = 7,
iPhone6Plus = 8,
iPhone6S = 9,
iPhone6SPlus = 10,
iPhoneSE = 11,
iPhone7 = 12,
iPhone7Plus = 13,
iPhone8 = 14,
iPhone8Plus = 15,
iPhoneX = 16,
iPhoneSE = 17,
iPhoneXS = 17,
iPhoneXSMax = 18,
iPhoneXR = 19,

iPad1 = 18,
iPad2 = 19,
iPadMini = 20,
iPad3 = 21,
iPad4 = 22,
iPadAir = 23,
iPadMini2 = 24,
iPadAir2 = 25,
iPadMini3 = 26,
iPadMini4 = 27,
iPadPro12Dot9Inch = 28,
iPadPro9Dot7Inch = 29,
iPad5 = 30,
iPadPro12Dot9Inch2Gen = 31,
iPadPro10Dot5Inch = 32,
iPad1 = 20,
iPad2 = 21,
iPadMini = 22,
iPad3 = 23,
iPad4 = 24,
iPadAir = 25,
iPadMini2 = 26,
iPadAir2 = 27,
iPadMini3 = 28,
iPadMini4 = 29,
iPadPro12Dot9Inch = 30,
iPadPro9Dot7Inch = 31,
iPad5 = 32,
iPadPro12Dot9Inch2Gen = 33,
iPadPro10Dot5Inch = 34,
iPad6 = 35,

iPodTouch1Gen = 33,
iPodTouch2Gen = 34,
iPodTouch3Gen = 35,
iPodTouch4Gen = 36,
iPodTouch5Gen = 37,
iPodTouch6Gen = 38
iPodTouch1Gen = 36,
iPodTouch2Gen = 37,
iPodTouch3Gen = 38,
iPodTouch4Gen = 39,
iPodTouch5Gen = 40,
iPodTouch6Gen = 41
};

typedef NS_ENUM(NSInteger, DeviceSize){
Expand All @@ -57,7 +61,9 @@ typedef NS_ENUM(NSInteger, DeviceSize){
Screen4inch = 2,
Screen4Dot7inch = 3,
Screen5Dot5inch = 4,
Screen5Dot8inch = 5
Screen5Dot8inch = 5,
Screen6Dot1inch = 6,
Screen6Dot5inch = 7
};

@interface SDiOSVersion : NSObject
Expand Down
36 changes: 27 additions & 9 deletions SDVersion/SDiOSVersion/SDiOSVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ + (NSDictionary*)deviceNamesByCode
@"iPhone10,5" : @(iPhone8Plus),
@"iPhone10,3" : @(iPhoneX),
@"iPhone10,6" : @(iPhoneX),
@"iPhone11,2" : @(iPhoneXS),
@"iPhone11,4" : @(iPhoneXSMax),
@"iPhone11,6" : @(iPhoneXSMax),
@"iPhone11,8" : @(iPhoneXR),
@"i386" : @(Simulator),
@"x86_64" : @(Simulator),

Expand Down Expand Up @@ -89,6 +93,8 @@ + (NSDictionary*)deviceNamesByCode
@"iPad7,2" : @(iPadPro12Dot9Inch2Gen),
@"iPad7,3" : @(iPadPro10Dot5Inch),
@"iPad7,4" : @(iPadPro10Dot5Inch),
@"iPad7,5" : @(iPad6),
@"iPad7,6" : @(iPad6),

//iPods
@"iPod1,1" : @(iPodTouch1Gen),
Expand All @@ -109,7 +115,7 @@ + (DeviceVersion)deviceVersion
uname(&systemInfo);
NSString *code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];

DeviceVersion version = (DeviceVersion)[[self.deviceNamesByCode objectForKey:code] integerValue];
DeviceVersion version = (DeviceVersion)[[[SDiOSVersion deviceNamesByCode] objectForKey:code] integerValue];

return version;
}
Expand All @@ -126,22 +132,28 @@ + (DeviceSize)resolutionSize

if (screenHeight == 480) {
return Screen3Dot5inch;
} else if(screenHeight == 568) {
} else if (screenHeight == 568) {
return Screen4inch;
} else if(screenHeight == 667) {
} else if (screenHeight == 667) {
return Screen4Dot7inch;
} else if(screenHeight == 736) {
} else if (screenHeight == 736) {
return Screen5Dot5inch;
} else if (screenHeight == 812) {
return Screen5Dot8inch;
} else if (screenHeight == 896) {
if ([SDiOSVersion deviceVersion] == iPhoneXSMax) {
return Screen6Dot5inch;
} else {
return Screen6Dot1inch;
}
} else
return UnknownSize;
}

+ (DeviceSize)deviceSize
{
DeviceSize deviceSize = [self resolutionSize];
if ([self isZoomed]) {
DeviceSize deviceSize = [SDiOSVersion resolutionSize];
if ([SDiOSVersion isZoomed]) {
if (deviceSize == Screen4inch) {
deviceSize = Screen4Dot7inch;
} else if (deviceSize == Screen4Dot7inch) {
Expand All @@ -160,6 +172,8 @@ + (NSString *)deviceSizeName:(DeviceSize)deviceSize
@(Screen4Dot7inch) : @"4.7 inch",
@(Screen5Dot5inch) : @"5.5 inch",
@(Screen5Dot8inch) : @"5.8 inch",
@(Screen6Dot1inch) : @"6.1 inch",
@(Screen6Dot5inch) : @"6.5 inch"
}[@(deviceSize)];
}

Expand All @@ -180,12 +194,15 @@ + (NSString *)deviceNameForVersion:(DeviceVersion)deviceVersion
@(iPhone6Plus) : @"iPhone 6 Plus",
@(iPhone6S) : @"iPhone 6S",
@(iPhone6SPlus) : @"iPhone 6S Plus",
@(iPhoneSE) : @"iPhone SE",
@(iPhone7) : @"iPhone 7",
@(iPhone7Plus) : @"iPhone 7 Plus",
@(iPhone8) : @"iPhone 8",
@(iPhone8Plus) : @"iPhone 8 Plus",
@(iPhoneX) : @"iPhone X",
@(iPhoneSE) : @"iPhone SE",
@(iPhoneXS) : @"iPhone XS",
@(iPhoneXSMax) : @"iPhone XS Max",
@(iPhoneXR) : @"iPhone XR",

@(iPad1) : @"iPad 1",
@(iPad2) : @"iPad 2",
Expand All @@ -202,6 +219,7 @@ + (NSString *)deviceNameForVersion:(DeviceVersion)deviceVersion
@(iPad5) : @"iPad 5",
@(iPadPro10Dot5Inch) : @"iPad Pro 10.5 inch",
@(iPadPro12Dot9Inch2Gen): @"iPad Pro 12.9 inch",
@(iPad6) : @"iPad 6",

@(iPodTouch1Gen) : @"iPod Touch 1st Gen",
@(iPodTouch2Gen) : @"iPod Touch 2nd Gen",
Expand All @@ -217,9 +235,9 @@ + (NSString *)deviceNameForVersion:(DeviceVersion)deviceVersion

+ (BOOL)isZoomed
{
if ([self resolutionSize] == Screen4inch && [UIScreen mainScreen].nativeScale > 2) {
if ([SDiOSVersion resolutionSize] == Screen4inch && [UIScreen mainScreen].nativeScale > 2) {
return YES;
}else if ([self resolutionSize] == Screen4Dot7inch && [UIScreen mainScreen].scale == 3){
} else if ([SDiOSVersion resolutionSize] == Screen4Dot7inch && [UIScreen mainScreen].scale == 3){
return YES;
}

Expand Down