Updated for iPhone 14, 14 Plus, 14 Pro and 14 Pro Max
Updated for iPhone 13 Mini, 13, 13 Pro and 13 Pro Max
public extension UIDevice {
var iPhone: Bool { UIDevice.current.userInterfaceIdiom == .phone }
var iPad: Bool { UIDevice().userInterfaceIdiom == .pad }
enum ScreenType: String {
case iPhones_4_4S = "iPhone 4 or iPhone 4S"
case iPhones_5_5s_5c_SE = "iPhone 5, iPhone 5s, iPhone 5c or iPhone SE"
case iPhones_6_6s_7_8 = "iPhone 6, iPhone 6S, iPhone 7 or iPhone 8"
case iPhones_6Plus_6sPlus_7Plus_8Plus = "iPhone 6 Plus, iPhone 6S Plus, iPhone 7 Plus or iPhone 8 Plus"
case iPhones_X_XS = "iPhone X or iPhone XS"
case iPhone_XR_11 = "iPhone XR or iPhone 11"
case iPhone_XSMax_ProMax = "iPhone XS Max or iPhone Pro Max"
case iPhone_11Pro = "iPhone 11 Pro"
case iPhone_12_12Pro_13_13Pro_14 = "iPhone 12 or 12 Pro or 13 or 13 Pro or 14"
case iPhone_14Pro = "iPhone 14 Pro"
case iPhone_12ProMax_13ProMax_14Plus = "iPhone 12 Pro Max or 13 Pro Max or 14 Plus"
case iPhone_14ProMax = "iPhone 14 Pro Max"
case iPhone12Mini_13Mini = "iPhone 12 Mini or 13 Mini"
case unknown
}
var screenType: ScreenType {
guard iPhone else { return .unknown }
switch UIScreen.main.nativeBounds.height {
case 960:
return .iPhones_4_4S
case 1136:
return .iPhones_5_5s_5c_SE
case 1334:
return .iPhones_6_6s_7_8
case 1792:
return .iPhone_XR_11
case 1920, 2208:
return .iPhones_6Plus_6sPlus_7Plus_8Plus
case 2340:
return .iPhone12Mini_13Mini
case 2426:
return .iPhone_11Pro
case 2436:
return .iPhones_X_XS
case 2532:
return .iPhone_12_12Pro_13_13Pro_14
case 2688:
return .iPhone_XSMax_ProMax
case 2778:
return .iPhone_12ProMax_13ProMax_14Plus
case 2556:
return .iPhone_14Pro
case 2796:
return .iPhone_14ProMax
default:
return .unknown
}
}
}