1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| public extension UIDevice { var deviceName: String { var systemInfo = utsname() uname(&systemInfo) let machineMirror = Mirror(reflecting: systemInfo.machine) let identifier = machineMirror.children.reduce("") {identifier, element in guard let value = element.value as? Int8, value != 0 else { return identifier } return identifier + String(UnicodeScalar(UInt8(value))) } switch identifier { case "iPhone5,1", "iPhone5,2", "iPhone5,3", "iPhone5,4", "iPhone6,1", "iPhone6,2": return "iPhone5" case "iPhone7,2", "iPhone8,1", "iPhone9,1", "iPhone9,3", "iPhone10,1": return "iPhone678" case "iPhone7,1", "iPhone8,2", "iPhone9,2", "iPhone9,4", "iPhone10,2", "iPhone10,5": return "iPhone678Plus" case "iPhone10,3", "iPhone10,6", "iPhone11,8", "iPhone11,2", "iPhone11,6": return "iPhoneXSeries" case "iPhone8,4": return "iPhoneSE" default: return identifier } } var isPhone5Series: Bool { return deviceName == "iPhone5" } var isPhone6Series: Bool { return deviceName == "iPhone678" } var isPhone6PSeries: Bool { return deviceName == "iPhone678Plus" } var isPhoneXSeries: Bool { return deviceName == "iPhoneXSeries" } }
|