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

Simulator with iPad devices and iPad size #87

Open
wants to merge 7 commits 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
54 changes: 31 additions & 23 deletions SDVersion/SDiOSVersion/SDiOSVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,46 @@ typedef NS_ENUM(NSInteger, DeviceVersion){
iPhone8Plus = 15,
iPhoneX = 16,
iPhoneSE = 17,
iPhoneXR = 18,
iPhoneXS = 19,
iPhoneXSMax = 20,

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 = 21,
iPad2 = 22,
iPadMini = 23,
iPad3 = 24,
iPad4 = 25,
iPadAir = 26,
iPadMini2 = 27,
iPadAir2 = 28,
iPadMini3 = 29,
iPadMini4 = 30,
iPadPro12Dot9Inch = 31,
iPadPro9Dot7Inch = 32,
iPad5 = 33,
iPadPro12Dot9Inch2Gen = 34,
iPadPro10Dot5Inch = 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){
UnknownSize = 0,
Screen3Dot5inch = 1,
Screen4inch = 2,
Screen4Dot7inch = 3,
Screen5Dot5inch = 4,
Screen5Dot8inch = 5
Screen5Dot5inch = 4, // plus
Screen5Dot8inch = 5, // X / XS
Screen6Dot1inch = 6, // XR scale 2
Screen6Dot5inch = 7, // XS Max scale 3
Screen9Dot7inch = 8,
Screen10Dot5inch = 9,
Screen12Dot9inch = 10,
};

@interface SDiOSVersion : NSObject
Expand Down
33 changes: 29 additions & 4 deletions SDVersion/SDiOSVersion/SDiOSVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ + (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 @@ -105,9 +111,18 @@ + (NSDictionary*)deviceNamesByCode

+ (DeviceVersion)deviceVersion
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
NSString *code = nil;

#if TARGET_OS_SIMULATOR
code = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"];
#endif // TARGET_OS_SIMULATOR

if (code == nil) {
struct utsname systemInfo;
uname(&systemInfo);
code = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}

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

Expand All @@ -133,7 +148,17 @@ + (DeviceSize)resolutionSize
} else if(screenHeight == 736) {
return Screen5Dot5inch;
} else if (screenHeight == 812) {
return Screen5Dot8inch;
return Screen5Dot8inch; // X / XS
} else if ((screenHeight == 896) && ([UIScreen mainScreen].scale == 2)) {
return Screen6Dot1inch; // XR
} else if ((screenHeight == 896) && ([UIScreen mainScreen].scale == 3)) {
return Screen6Dot5inch; // XS MAX
} else if (screenHeight == 1366) {
return Screen12Dot9inch;
} else if (screenHeight == 1112) {
return Screen10Dot5inch;
} else if (screenHeight == 1024) {
return Screen9Dot7inch;
} else
return UnknownSize;
}
Expand Down
15 changes: 12 additions & 3 deletions SDVersion/SDtvOSVersion/SDtvOSVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ + (NSDictionary*)deviceNamesByCode

+ (DeviceVersion)deviceVersion
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
NSString *code = nil;

#if TARGET_OS_SIMULATOR
code = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"];
#endif // TARGET_OS_SIMULATOR

if (code == nil) {
struct utsname systemInfo;
uname(&systemInfo);
code = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}

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

return version;
Expand Down
15 changes: 12 additions & 3 deletions SDVersion/SDwatchOSVersion/SDwatchOSVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@ + (NSDictionary*)deviceNamesByCode

+ (DeviceVersion)deviceVersion
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
NSString *code = nil;

#if TARGET_OS_SIMULATOR
code = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"];
#endif // TARGET_OS_SIMULATOR

if (code == nil) {
struct utsname systemInfo;
uname(&systemInfo);
code = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}

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

return version;
Expand Down