Created
November 9, 2018 13:19
-
-
Save astrokin/02b65741470e5c2b4ce9475dd53f77d6 to your computer and use it in GitHub Desktop.
UIDevice type detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension UIDevice { | |
public enum `Type` { | |
case iPad | |
case iPhone_unknown | |
case iPhone_5_5S_5C | |
case iPhone_6_6S_7_8 | |
case iPhone_6_6S_7_8_PLUS | |
case iPhone_X_Xs | |
case iPhone_Xs_Max | |
case iPhone_Xr | |
} | |
public var hasHomeButton: Bool { | |
switch type { | |
case .iPhone_X_Xs, .iPhone_Xr, .iPhone_Xs_Max: | |
return false | |
default: | |
return true | |
} | |
} | |
public var type: Type { | |
if userInterfaceIdiom == .phone { | |
switch UIScreen.main.nativeBounds.height { | |
case 1136: | |
return .iPhone_5_5S_5C | |
case 1334: | |
return .iPhone_6_6S_7_8 | |
case 1920, 2208: | |
return .iPhone_6_6S_7_8_PLUS | |
case 2436: | |
return .iPhone_X_Xs | |
case 2688: | |
return .iPhone_Xs_Max | |
case 1792: | |
return .iPhone_Xr | |
default: | |
return .iPhone_unknown | |
} | |
} | |
return .iPad | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment