diff --git a/.swift-version b/.swift-version index bf77d549..819e07a2 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.2 +5.0 diff --git a/.travis.yml b/.travis.yml index 49137279..c42b881f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode10.1 +osx_image: xcode10.2 env: - DESTINATION='platform=iOS Simulator,name=iPad (5th generation)' diff --git a/DeviceKit.xcodeproj/project.pbxproj b/DeviceKit.xcodeproj/project.pbxproj index 7fba1f90..5fe48e93 100644 --- a/DeviceKit.xcodeproj/project.pbxproj +++ b/DeviceKit.xcodeproj/project.pbxproj @@ -210,12 +210,12 @@ }; 955EE5991D5E581B008C3DA8 = { CreatedOnToolsVersion = 8.0; - LastSwiftMigration = 0900; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; 955EE5A11D5E581B008C3DA8 = { CreatedOnToolsVersion = 8.0; - LastSwiftMigration = 0900; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; }; @@ -225,6 +225,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 95CBDB631BFD2B440065FC66; @@ -384,7 +385,7 @@ SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2,3"; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -437,7 +438,7 @@ RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2,3"; TVOS_DEPLOYMENT_TARGET = 9.0; VALIDATE_PRODUCT = YES; @@ -489,7 +490,7 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OBJC_INTERFACE_HEADER_NAME = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -530,7 +531,7 @@ SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OBJC_INTERFACE_HEADER_NAME = ""; SWIFT_OPTIMIZATION_LEVEL = "-O"; - SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 5.0; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/README.md b/README.md index c179e2a1..76c0feee 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ | Branch | Build Status | Versions | |:---------|:--------------:|:----------:| | **master** |[![Build Status](https://travis-ci.org/devicekit/DeviceKit.svg?branch=master)](https://travis-ci.org/devicekit/DeviceKit)| - | -| **Swift 4 - 4.2** |[![Build Status](https://travis-ci.org/devicekit/DeviceKit.svg?branch=swift-4)](https://travis-ci.org/devicekit/DeviceKit)| ≥ 1.3 | +| **Swift 5** |[![Build Status](https://travis-ci.org/devicekit/DeviceKit.svg?branch=swift-5)](https://travis-ci.org/devicekit/DeviceKit)| ≥ 2.0 | +| **Swift 4 - 4.2** |[![Build Status](https://travis-ci.org/devicekit/DeviceKit.svg?branch=swift-4)](https://travis-ci.org/devicekit/DeviceKit)| ≥ 1.3 < 1.13 | | **Swift 3** |[![Build Status](https://travis-ci.org/devicekit/DeviceKit.svg?branch=swift-3)](https://travis-ci.org/devicekit/DeviceKit)| ≥ 1.0 < 1.3 | | **Swift 2.3** |[![Build Status](https://travis-ci.org/devicekit/DeviceKit.svg?branch=swift-2.3-unsupported)](https://travis-ci.org/devicekit/DeviceKit)| < 1.0 | @@ -47,6 +48,10 @@ DeviceKit can be installed in various ways. ### CocoaPods +#### Swift 5 +```ruby +pod 'DeviceKit', '~> 2.0' +``` #### Swift 4.0 - Swift 4.2 ```ruby pod 'DeviceKit', '~> 1.3' @@ -62,6 +67,10 @@ pod 'DeviceKit', :git => 'https://github.com/devicekit/DeviceKit.git', :branch = ### Carthage +#### Swift 5 +```ogdl +github "devicekit/DeviceKit" ~> 2.0 +``` #### Swift 4.0 - Swift 4.2 ```ogdl github "devicekit/DeviceKit" ~> 1.3 @@ -101,7 +110,7 @@ You can try these examples in Playground. ### Get the Device You're Running On ```swift -let device = Device() +let device = Device.current print(device) // prints, for example, "iPhone 6 Plus" @@ -114,7 +123,7 @@ if device == .iPhone6Plus { ### Get the Device Family ```swift -let device = Device() +let device = Device.current if device.isPod { // iPods (real or simulator) } else if device.isPhone { @@ -126,7 +135,7 @@ if device.isPod { ### Check If Running on Simulator ```swift -let device = Device() +let device = Device.current if device.isSimulator { // Running on one of the simulators(iPod/iPhone/iPad) // Skip doing something irrelevant for Simulator @@ -135,7 +144,7 @@ if device.isSimulator { ### Get the Simulator Device ```swift -let device = Device() +let device = Device.current switch device { case .simulator(.iPhone6s): break // You're running on the iPhone 6s simulator case .simulator(.iPadAir2): break // You're running on the iPad Air 2 simulator @@ -145,9 +154,9 @@ default: break ### Make Sure the Device Is Contained in a Preconfigured Group ```swift -let groupOfAllowedDevices: [Device] = [.iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .simulator(.iPhone6), .simulator(.iPhone6Plus),.simulator(.iPhone6s),.simulator(.iPhone6sPlus).simulator(.iPhone8),.simulator(.iPhone8Plus),.simulator(.iPhoneX),.simulator(.iPhoneXs),.simulator(.iPhoneXsMax),.simulator(.iPhoneXr)] +let groupOfAllowedDevices: [Device] = [.iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .simulator(.iPhone6), .simulator(.iPhone6Plus),.simulator(.iPhone6s),.simulator(.iPhone6sPlus).simulator(.iPhone8),.simulator(.iPhone8Plus),.simulator(.iPhoneX),.simulator(.iPhoneXS),.simulator(.iPhoneXSMax),.simulator(.iPhoneXR)] -let device = Device() +let device = Device.current if device.isOneOf(groupOfAllowedDevices) { // Do your action diff --git a/Source/Device.generated.swift b/Source/Device.generated.swift index 468e128d..b4dfa598 100644 --- a/Source/Device.generated.swift +++ b/Source/Device.generated.swift @@ -22,7 +22,7 @@ import UIKit /// /// Usage: /// -/// let device = Device() +/// let device = Device.current /// /// print(device) // prints, for example, "iPhone 6 Plus" /// @@ -119,15 +119,15 @@ public enum Device { /// Device is an [iPhone Xs](https://support.apple.com/kb/SP779) /// /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP779/SP779-iphone-xs.jpg) - case iPhoneXs + case iPhoneXS /// Device is an [iPhone Xs Max](https://support.apple.com/kb/SP780) /// /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP780/SP780-iPhone-Xs-Max.jpg) - case iPhoneXsMax - /// Device is an [iPhone Xr](https://support.apple.com/kb/SP781) + case iPhoneXSMax + /// Device is an [iPhone Xʀ](https://support.apple.com/kb/SP781) /// /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP781/SP781-iPhone-xr.jpg) - case iPhoneXr + case iPhoneXR /// Device is an [iPad 2](https://support.apple.com/kb/SP622) /// /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP622/SP622_01-ipad2-mul.png) @@ -148,17 +148,17 @@ public enum Device { /// /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP708/SP708-space_gray.jpeg) case iPadAir2 - /// Device is an [iPad 5](https://support.apple.com/kb/SP751) + /// Device is an [iPad (5th generation)](https://support.apple.com/kb/SP751) /// /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP751/ipad_5th_generation.png) case iPad5 - /// Device is an [iPad 6](https://support.apple.com/kb/NotYetAvailable) + /// Device is an [iPad (6th generation)](https://support.apple.com/kb/SP774) /// /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP751/ipad_5th_generation.png) case iPad6 - /// Device is an [iPad Air (3rd generation)](INSERT LINK) + /// Device is an [iPad Air (3rd generation)](https://support.apple.com/kb/SP787) /// - /// ![Image](https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/image/AppleInc/aos/published/images/i/pa/ipad/mini/ipad-mini-compare-201903) + /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP787/ipad-air-2019.jpg) case iPadAir3 /// Device is an [iPad Mini](https://support.apple.com/kb/SP661) /// @@ -176,17 +176,17 @@ public enum Device { /// /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP725/SP725ipad-mini-4.png) case iPadMini4 - /// Device is an [iPad Mini (5th generation)](INSERT LINK) + /// Device is an [iPad Mini (5th generation)](https://support.apple.com/kb/SP788) /// - /// ![Image](https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/image/AppleInc/aos/published/images/i/pa/ipad/air/ipad-air-compare-201903) + /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP788/ipad-mini-2019.jpg) case iPadMini5 /// Device is an [iPad Pro 9.7-inch](https://support.apple.com/kb/SP739) /// /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP739/SP739.png) case iPadPro9Inch - /// Device is an [iPad Pro 12-inch](https://support.apple.com/kb/sp723) + /// Device is an [iPad Pro 12-inch](https://support.apple.com/kb/SP723) /// - /// ![Image](http://images.apple.com/v/ipad-pro/c/images/shared/buystrip/ipad_pro_large_2x.png) + /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP723/SP723-iPad_Pro_2x.png) case iPadPro12Inch /// Device is an [iPad Pro 12-inch (2nd generation)](https://support.apple.com/kb/SP761) /// @@ -196,17 +196,17 @@ public enum Device { /// /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP761/ipad-pro-10in-hero-201706.png) case iPadPro10Inch - /// Device is an [iPad Pro 11-inch](https://support.apple.com/kb/not-published-yet) + /// Device is an [iPad Pro 11-inch](https://support.apple.com/kb/SP784) /// - /// ![Image](https://support.apple.com/not-published-yet) + /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP784/ipad-pro-11-2018_2x.png) case iPadPro11Inch - /// Device is an [iPad Pro 12.9-inch (3rd generation)](https://support.apple.com/kb/not-published-yet) + /// Device is an [iPad Pro 12.9-inch (3rd generation)](https://support.apple.com/kb/SP785) /// - /// ![Image](https://support.apple.com/not-published-yet) + /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP785/ipad-pro-12-2018_2x.png) case iPadPro12Inch3 - /// Device is a [HomePod](https://www.apple.com/homepod/) + /// Device is a [HomePod](https://support.apple.com/kb/SP773) /// - /// ![Image](https://images.apple.com/v/homepod/d/images/overview/homepod_side_dark_large_2x.jpg) + /// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP773/homepod_space_gray_large_2x.jpg) case homePod #elseif os(tvOS) /// Device is an [Apple TV 4](https://support.apple.com/kb/SP724) @@ -270,9 +270,9 @@ public enum Device { /// (e.g. "iPhone6,1" or "iPhone 6,2" do both mean "iPhone 5s")) case unknown(String) - /// Initializes a `Device` representing the current device this software runs on. - public init() { - self = Device.instance + /// Returns a `Device` representing the current device this software runs on. + public static var current: Device { + return Device.mapToDevice(identifier: Device.identifier) } /// Gets the identifier from the system, such as "iPhone7,1". @@ -288,14 +288,12 @@ public enum Device { return identifier }() - private static let instance = Device.mapToDevice(identifier: Device.identifier) - /// Maps an identifier to a Device. If the identifier can not be mapped to an existing device, `UnknownDevice(identifier)` is returned. /// /// - parameter identifier: The device identifier, e.g. "iPhone7,1". Can be obtained from `Device.identifier`. /// /// - returns: An initialized `Device`. - public static func mapToDevice(identifier: String) -> Device { // swiftlint:disable:this cyclomatic_complexity + public static func mapToDevice(identifier: String) -> Device { // swiftlint:disable:this cyclomatic_complexity function_body_length #if os(iOS) switch identifier { case "iPod5,1": return iPodTouch5 @@ -315,9 +313,9 @@ public enum Device { case "iPhone10,1", "iPhone10,4": return iPhone8 case "iPhone10,2", "iPhone10,5": return iPhone8Plus case "iPhone10,3", "iPhone10,6": return iPhoneX - case "iPhone11,2": return iPhoneXs - case "iPhone11,4", "iPhone11,6": return iPhoneXsMax - case "iPhone11,8": return iPhoneXr + case "iPhone11,2": return iPhoneXS + case "iPhone11,4", "iPhone11,6": return iPhoneXSMax + case "iPhone11,8": return iPhoneXR case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4": return iPad2 case "iPad3,1", "iPad3,2", "iPad3,3": return iPad3 case "iPad3,4", "iPad3,5", "iPad3,6": return iPad4 @@ -403,9 +401,9 @@ public enum Device { case .iPhone8: return 4.7 case .iPhone8Plus: return 5.5 case .iPhoneX: return 5.8 - case .iPhoneXs: return 5.8 - case .iPhoneXsMax: return 6.5 - case .iPhoneXr: return 6.1 + case .iPhoneXS: return 5.8 + case .iPhoneXSMax: return 6.5 + case .iPhoneXR: return 6.1 case .iPad2: return 9.7 case .iPad3: return 9.7 case .iPad4: return 9.7 @@ -469,9 +467,9 @@ public enum Device { case .iPhone8: return (width: 9, height: 16) case .iPhone8Plus: return (width: 9, height: 16) case .iPhoneX: return (width: 9, height: 19.5) - case .iPhoneXs: return (width: 9, height: 19.5) - case .iPhoneXsMax: return (width: 9, height: 19.5) - case .iPhoneXr: return (width: 9, height: 19.5) + case .iPhoneXS: return (width: 9, height: 19.5) + case .iPhoneXSMax: return (width: 9, height: 19.5) + case .iPhoneXR: return (width: 9, height: 19.5) case .iPad2: return (width: 3, height: 4) case .iPad3: return (width: 3, height: 4) case .iPad4: return (width: 3, height: 4) @@ -523,7 +521,7 @@ public enum Device { /// All iPhones public static var allPhones: [Device] { - return [.iPhone4, .iPhone4s, .iPhone5, .iPhone5c, .iPhone5s, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhoneSE, .iPhone8, .iPhone8Plus, .iPhoneX, .iPhoneXs, .iPhoneXsMax, .iPhoneXr] + return [.iPhone4, .iPhone4s, .iPhone5, .iPhone5c, .iPhone5s, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhoneSE, .iPhone8, .iPhone8Plus, .iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR] } /// All iPads @@ -533,7 +531,7 @@ public enum Device { /// All X-Series Devices public static var allXSeriesDevices: [Device] { - return [.iPhoneX, .iPhoneXs, .iPhoneXsMax, .iPhoneXr] + return [.iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR] } /// All Plus-Sized Devices @@ -595,14 +593,14 @@ public enum Device { public var isPhone: Bool { return (isOneOf(Device.allPhones) || isOneOf(Device.allSimulatorPhones) - || UIDevice.current.userInterfaceIdiom == .phone) && !isPod + || (UIDevice.current.userInterfaceIdiom == .phone && isCurrent)) && !isPod } /// Returns whether the device is an iPad (real or simulator) public var isPad: Bool { return isOneOf(Device.allPads) || isOneOf(Device.allSimulatorPads) - || UIDevice.current.userInterfaceIdiom == .pad + || (UIDevice.current.userInterfaceIdiom == .pad && isCurrent) } /// Returns whether the device is any of the simulator @@ -617,9 +615,10 @@ public enum Device { return Device.realDevice(from: self) } - public var isZoomed: Bool { + public var isZoomed: Bool? { + guard isCurrent else { return nil } // TODO: Longterm we need a better solution for this! - guard self != .iPhoneX && self != .iPhoneXs else { return false } + guard self != .iPhoneX && self != .iPhoneXS else { return false } if Int(UIScreen.main.scale.rounded()) == 3 { // Plus-sized return UIScreen.main.nativeScale > 2.7 @@ -635,7 +634,7 @@ public enum Device { /// All Face ID Capable Devices public static var allFaceIDCapableDevices: [Device] { - return [.iPhoneX, .iPhoneXs, .iPhoneXsMax, .iPhoneXr, .iPadPro11Inch, .iPadPro12Inch3] + return [.iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR, .iPadPro11Inch, .iPadPro12Inch3] } /// Returns whether or not the device has Touch ID @@ -653,6 +652,26 @@ public enum Device { return isTouchIDCapable || isFaceIDCapable } + /// All devices that feature a sensor housing in the screen + public static var allDevicesWithSensorHousing: [Device] { + return [.iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR] + } + + /// Returns whether or not the device has a sensor housing + public var hasSensorHousing: Bool { + return isOneOf(Device.allDevicesWithSensorHousing) + } + + /// All devices that feature a screen with rounded corners. + public static var allDevicesWithRoundedDisplayCorners: [Device] { + return [.iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR, .iPadPro11Inch, .iPadPro12Inch3] + } + + /// Returns whether or not the device has a screen with rounded corners. + public var hasRoundedDisplayCorners: Bool { + return isOneOf(Device.allDevicesWithRoundedDisplayCorners) + } + #elseif os(tvOS) /// All TVs public static var allTVs: [Device] { @@ -696,7 +715,7 @@ public enum Device { Most uses for an enum like this are the following: ``` - switch Device() { + switch Device.current { case .iPodTouch5, .iPodTouch6: callMethodOnIPods() case .iPhone4, iPhone4s, .iPhone5, .iPhone5s, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhoneSE, .iPhone8, .iPhone8Plus, .iPhoneX: callMethodOnIPhones() case .iPad2, .iPad3, .iPad4, .iPadAir, .iPadAir2, .iPadMini, .iPadMini2, .iPadMini3, .iPadMini4, .iPadPro: callMethodOnIPads() @@ -706,7 +725,7 @@ public enum Device { This code can now be replaced with ``` - let device = Device() + let device = Device.current if device.isOneOf(Device.allPods) { callMethodOnIPods() } else if device.isOneOf(Device.allPhones) { @@ -724,8 +743,14 @@ public enum Device { return devices.contains(self) } + /// Whether or not the current device is the current device. + private var isCurrent: Bool { + return self == Device.current + } + /// The name identifying the device (e.g. "Dennis' iPhone"). - public var name: String { + public var name: String? { + guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().name #else @@ -734,7 +759,8 @@ public enum Device { } /// The name of the operating system running on the device represented by the receiver (e.g. "iOS" or "tvOS"). - public var systemName: String { + public var systemName: String? { + guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().systemName #else @@ -743,7 +769,8 @@ public enum Device { } /// The current version of the operating system (e.g. 8.4 or 9.2). - public var systemVersion: String { + public var systemVersion: String? { + guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().systemVersion #else @@ -752,7 +779,8 @@ public enum Device { } /// The model of the device (e.g. "iPhone" or "iPod Touch"). - public var model: String { + public var model: String? { + guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().model #else @@ -761,7 +789,8 @@ public enum Device { } /// The model of the device as a localized string. - public var localizedModel: String { + public var localizedModel: String? { + guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().localizedModel #else @@ -790,9 +819,9 @@ public enum Device { case .iPhone8: return 326 case .iPhone8Plus: return 401 case .iPhoneX: return 458 - case .iPhoneXs: return 458 - case .iPhoneXsMax: return 458 - case .iPhoneXr: return 326 + case .iPhoneXS: return 458 + case .iPhoneXSMax: return 458 + case .iPhoneXR: return 326 case .iPad2: return 132 case .iPad3: return 264 case .iPad4: return 264 @@ -883,16 +912,16 @@ extension Device: CustomStringConvertible { case .iPhone8: return "iPhone 8" case .iPhone8Plus: return "iPhone 8 Plus" case .iPhoneX: return "iPhone X" - case .iPhoneXs: return "iPhone Xs" - case .iPhoneXsMax: return "iPhone Xs Max" - case .iPhoneXr: return "iPhone Xr" + case .iPhoneXS: return "iPhone Xs" + case .iPhoneXSMax: return "iPhone Xs Max" + case .iPhoneXR: return "iPhone Xʀ" case .iPad2: return "iPad 2" - case .iPad3: return "iPad 3" - case .iPad4: return "iPad 4" + case .iPad3: return "iPad (3rd generation)" + case .iPad4: return "iPad (4th generation)" case .iPadAir: return "iPad Air" case .iPadAir2: return "iPad Air 2" - case .iPad5: return "iPad 5" - case .iPad6: return "iPad 6" + case .iPad5: return "iPad (5th generation)" + case .iPad6: return "iPad (6th generation)" case .iPadAir3: return "iPad Air (3rd generation)" case .iPadMini: return "iPad Mini" case .iPadMini2: return "iPad Mini 2" @@ -980,8 +1009,10 @@ extension Device { switch UIDevice.current.batteryState { case .charging: self = .charging(batteryLevel) case .full: self = .full - case .unplugged:self = .unplugged(batteryLevel) + case .unplugged: self = .unplugged(batteryLevel) case .unknown: self = .full // Should never happen since `batteryMonitoring` is enabled. + @unknown default: + self = .full // To cover any future additions for which DeviceKit might not have updated yet. } UIDevice.current.isBatteryMonitoringEnabled = wasBatteryMonitoringEnabled } @@ -994,8 +1025,10 @@ extension Device { switch WKInterfaceDevice.current().batteryState { case .charging: self = .charging(batteryLevel) case .full: self = .full - case .unplugged:self = .unplugged(batteryLevel) + case .unplugged: self = .unplugged(batteryLevel) case .unknown: self = .full // Should never happen since `batteryMonitoring` is enabled. + @unknown default: + self = .full // To cover any future additions for which DeviceKit might not have updated yet. } WKInterfaceDevice.current().isBatteryMonitoringEnabled = wasBatteryMonitoringEnabled } @@ -1028,12 +1061,14 @@ extension Device { } /// The state of the battery - public var batteryState: BatteryState { + public var batteryState: BatteryState? { + guard isCurrent else { return nil } return BatteryState() } /// Battery level ranges from 0 (fully discharged) to 100 (100% charged). - public var batteryLevel: Int { + public var batteryLevel: Int? { + guard isCurrent else { return nil } switch BatteryState() { case .charging(let value): return value case .full: return 100 diff --git a/Source/Device.swift.gyb b/Source/Device.swift.gyb index 9c8dd4b3..9ea67c59 100644 --- a/Source/Device.swift.gyb +++ b/Source/Device.swift.gyb @@ -12,7 +12,7 @@ %{ class Device: - def __init__(self, caseName, comment, imageURL, identifiers, diagonal, screenRatio, description, ppi, isPlusFormFactor, isPadMiniFormFactor, isPro, isXSeries, hasTouchID, hasFaceID): + def __init__(self, caseName, comment, imageURL, identifiers, diagonal, screenRatio, description, ppi, isPlusFormFactor, isPadMiniFormFactor, isPro, isXSeries, hasTouchID, hasFaceID, hasSensorHousing, hasRoundedDisplayCorners): self.caseName = caseName self.comment = comment self.imageURL = imageURL @@ -27,64 +27,66 @@ class Device: self.isXSeries = isXSeries self.hasTouchID = hasTouchID self.hasFaceID = hasFaceID + self.hasSensorHousing = hasSensorHousing + self.hasRoundedDisplayCorners = hasRoundedDisplayCorners # iOS iPods = [ - Device("iPodTouch5", "Device is an [iPod Touch (5th generation)](https://support.apple.com/kb/SP657)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP657/sp657_ipod-touch_size.jpg", ["iPod5,1"], 4, (9, 16), "iPod Touch 5", 326, False, False, False, False, False, False), - Device("iPodTouch6", "Device is an [iPod Touch (6th generation)](https://support.apple.com/kb/SP720)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP720/SP720-ipod-touch-specs-color-sg-2015.jpg", ["iPod7,1"], 4, (9, 16), "iPod Touch 6", 326, False, False, False, False, False, False) + Device("iPodTouch5", "Device is an [iPod Touch (5th generation)](https://support.apple.com/kb/SP657)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP657/sp657_ipod-touch_size.jpg", ["iPod5,1"], 4, (9, 16), "iPod Touch 5", 326, False, False, False, False, False, False, False, False), + Device("iPodTouch6", "Device is an [iPod Touch (6th generation)](https://support.apple.com/kb/SP720)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP720/SP720-ipod-touch-specs-color-sg-2015.jpg", ["iPod7,1"], 4, (9, 16), "iPod Touch 6", 326, False, False, False, False, False, False, False, False) ] iPhones = [ - Device("iPhone4", "Device is an [iPhone 4](https://support.apple.com/kb/SP587)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP643/sp643_iphone4s_color_black.jpg", ["iPhone3,1", "iPhone3,2", "iPhone3,3"], 3.5, (2, 3), "iPhone 4", 326, False, False, False, False, False, False), - Device("iPhone4s", "Device is an [iPhone 4s](https://support.apple.com/kb/SP643)", "https://support.apple.com/library/content/dam/edam/applecare/images/en_US/iphone/iphone5s/iphone_4s.png", ["iPhone4,1"], 3.5, (2, 3), "iPhone 4s", 326, False, False, False, False, False, False), - Device("iPhone5", "Device is an [iPhone 5](https://support.apple.com/kb/SP655)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP655/sp655_iphone5_color.jpg", ["iPhone5,1", "iPhone5,2"], 4, (9, 16), "iPhone 5", 326, False, False, False, False, False, False), - Device("iPhone5c", "Device is an [iPhone 5c](https://support.apple.com/kb/SP684)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP684/SP684-color_yellow.jpg", ["iPhone5,3", "iPhone5,4"], 4, (9, 16), "iPhone 5c", 326, False, False, False, False, False, False), - Device("iPhone5s", "Device is an [iPhone 5s](https://support.apple.com/kb/SP685)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP685/SP685-color_black.jpg", ["iPhone6,1", "iPhone6,2"], 4, (9, 16), "iPhone 5s", 326, False, False, False, False, True, False), - Device("iPhone6", "Device is an [iPhone 6](https://support.apple.com/kb/SP705)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP705/SP705-iphone_6-mul.png", ["iPhone7,2"], 4.7, (9, 16), "iPhone 6", 326, False, False, False, False, True, False), - Device("iPhone6Plus", "Device is an [iPhone 6 Plus](https://support.apple.com/kb/SP706)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP706/SP706-iphone_6_plus-mul.png", ["iPhone7,1"], 5.5, (9, 16), "iPhone 6 Plus", 401, True, False, False, False, True, False), - Device("iPhone6s", "Device is an [iPhone 6s](https://support.apple.com/kb/SP726)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP726/SP726-iphone6s-gray-select-2015.png", ["iPhone8,1"], 4.7, (9, 16), "iPhone 6s", 326, False, False, False, False, True, False), - Device("iPhone6sPlus", "Device is an [iPhone 6s Plus](https://support.apple.com/kb/SP727)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP727/SP727-iphone6s-plus-gray-select-2015.png", ["iPhone8,2"], 5.5, (9, 16), "iPhone 6s Plus", 401, True, False, False, False, True, False), - Device("iPhone7", "Device is an [iPhone 7](https://support.apple.com/kb/SP743)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP743/iphone7-black.png", ["iPhone9,1", "iPhone9,3"], 4.7, (9, 16), "iPhone 7", 326, False, False, False, False, True, False), - Device("iPhone7Plus", "Device is an [iPhone 7 Plus](https://support.apple.com/kb/SP744)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP744/iphone7-plus-black.png", ["iPhone9,2", "iPhone9,4"], 5.5, (9, 16), "iPhone 7 Plus", 401, True, False, False, False, True, False), - Device("iPhoneSE", "Device is an [iPhone SE](https://support.apple.com/kb/SP738)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP738/SP738.png", ["iPhone8,4"], 4, (9, 16), "iPhone SE", 326, False, False, False, False, True, False), - Device("iPhone8", "Device is an [iPhone 8](https://support.apple.com/kb/SP767)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP767/iphone8.png", ["iPhone10,1", "iPhone10,4"], 4.7, (9, 16), "iPhone 8", 326, False, False, False, False, True, False), - Device("iPhone8Plus", "Device is an [iPhone 8 Plus](https://support.apple.com/kb/SP768)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP768/iphone8plus.png", ["iPhone10,2", "iPhone10,5"], 5.5, (9, 16), "iPhone 8 Plus", 401, True, False, False, False, True, False), - Device("iPhoneX", "Device is an [iPhone X](https://support.apple.com/kb/SP770)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP770/iphonex.png", ["iPhone10,3", "iPhone10,6"], 5.8, (9, 19.5), "iPhone X", 458, False, False, False, True, False, True), - Device("iPhoneXs", "Device is an [iPhone Xs](https://support.apple.com/kb/SP779)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP779/SP779-iphone-xs.jpg", ["iPhone11,2"], 5.8, (9, 19.5), "iPhone Xs", 458, False, False, False, True, False, True), - Device("iPhoneXsMax", "Device is an [iPhone Xs Max](https://support.apple.com/kb/SP780)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP780/SP780-iPhone-Xs-Max.jpg", ["iPhone11,4", "iPhone11,6"], 6.5, (9, 19.5), "iPhone Xs Max", 458, False, False, False, True, False, True), - Device("iPhoneXr", "Device is an [iPhone Xr](https://support.apple.com/kb/SP781)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP781/SP781-iPhone-xr.jpg", ["iPhone11,8"], 6.1, (9, 19.5), "iPhone Xr", 326, False, False, False, True, False, True) + Device("iPhone4", "Device is an [iPhone 4](https://support.apple.com/kb/SP587)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP643/sp643_iphone4s_color_black.jpg", ["iPhone3,1", "iPhone3,2", "iPhone3,3"], 3.5, (2, 3), "iPhone 4", 326, False, False, False, False, False, False, False, False), + Device("iPhone4s", "Device is an [iPhone 4s](https://support.apple.com/kb/SP643)", "https://support.apple.com/library/content/dam/edam/applecare/images/en_US/iphone/iphone5s/iphone_4s.png", ["iPhone4,1"], 3.5, (2, 3), "iPhone 4s", 326, False, False, False, False, False, False, False, False), + Device("iPhone5", "Device is an [iPhone 5](https://support.apple.com/kb/SP655)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP655/sp655_iphone5_color.jpg", ["iPhone5,1", "iPhone5,2"], 4, (9, 16), "iPhone 5", 326, False, False, False, False, False, False, False, False), + Device("iPhone5c", "Device is an [iPhone 5c](https://support.apple.com/kb/SP684)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP684/SP684-color_yellow.jpg", ["iPhone5,3", "iPhone5,4"], 4, (9, 16), "iPhone 5c", 326, False, False, False, False, False, False, False, False), + Device("iPhone5s", "Device is an [iPhone 5s](https://support.apple.com/kb/SP685)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP685/SP685-color_black.jpg", ["iPhone6,1", "iPhone6,2"], 4, (9, 16), "iPhone 5s", 326, False, False, False, False, True, False, False, False), + Device("iPhone6", "Device is an [iPhone 6](https://support.apple.com/kb/SP705)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP705/SP705-iphone_6-mul.png", ["iPhone7,2"], 4.7, (9, 16), "iPhone 6", 326, False, False, False, False, True, False, False, False), + Device("iPhone6Plus", "Device is an [iPhone 6 Plus](https://support.apple.com/kb/SP706)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP706/SP706-iphone_6_plus-mul.png", ["iPhone7,1"], 5.5, (9, 16), "iPhone 6 Plus", 401, True, False, False, False, True, False, False, False), + Device("iPhone6s", "Device is an [iPhone 6s](https://support.apple.com/kb/SP726)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP726/SP726-iphone6s-gray-select-2015.png", ["iPhone8,1"], 4.7, (9, 16), "iPhone 6s", 326, False, False, False, False, True, False, False, False), + Device("iPhone6sPlus", "Device is an [iPhone 6s Plus](https://support.apple.com/kb/SP727)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP727/SP727-iphone6s-plus-gray-select-2015.png", ["iPhone8,2"], 5.5, (9, 16), "iPhone 6s Plus", 401, True, False, False, False, True, False, False, False), + Device("iPhone7", "Device is an [iPhone 7](https://support.apple.com/kb/SP743)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP743/iphone7-black.png", ["iPhone9,1", "iPhone9,3"], 4.7, (9, 16), "iPhone 7", 326, False, False, False, False, True, False, False, False), + Device("iPhone7Plus", "Device is an [iPhone 7 Plus](https://support.apple.com/kb/SP744)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP744/iphone7-plus-black.png", ["iPhone9,2", "iPhone9,4"], 5.5, (9, 16), "iPhone 7 Plus", 401, True, False, False, False, True, False, False, False), + Device("iPhoneSE", "Device is an [iPhone SE](https://support.apple.com/kb/SP738)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP738/SP738.png", ["iPhone8,4"], 4, (9, 16), "iPhone SE", 326, False, False, False, False, True, False, False, False), + Device("iPhone8", "Device is an [iPhone 8](https://support.apple.com/kb/SP767)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP767/iphone8.png", ["iPhone10,1", "iPhone10,4"], 4.7, (9, 16), "iPhone 8", 326, False, False, False, False, True, False, False, False), + Device("iPhone8Plus", "Device is an [iPhone 8 Plus](https://support.apple.com/kb/SP768)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP768/iphone8plus.png", ["iPhone10,2", "iPhone10,5"], 5.5, (9, 16), "iPhone 8 Plus", 401, True, False, False, False, True, False, False, False), + Device("iPhoneX", "Device is an [iPhone X](https://support.apple.com/kb/SP770)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP770/iphonex.png", ["iPhone10,3", "iPhone10,6"], 5.8, (9, 19.5), "iPhone X", 458, False, False, False, True, False, True, True, True), + Device("iPhoneXS", "Device is an [iPhone Xs](https://support.apple.com/kb/SP779)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP779/SP779-iphone-xs.jpg", ["iPhone11,2"], 5.8, (9, 19.5), "iPhone Xs", 458, False, False, False, True, False, True, True, True), + Device("iPhoneXSMax", "Device is an [iPhone Xs Max](https://support.apple.com/kb/SP780)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP780/SP780-iPhone-Xs-Max.jpg", ["iPhone11,4", "iPhone11,6"], 6.5, (9, 19.5), "iPhone Xs Max", 458, False, False, False, True, False, True, True, True), + Device("iPhoneXR", "Device is an [iPhone Xʀ](https://support.apple.com/kb/SP781)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP781/SP781-iPhone-xr.jpg", ["iPhone11,8"], 6.1, (9, 19.5), "iPhone Xʀ", 326, False, False, False, True, False, True, True, True) ] iPads = [ - Device("iPad2", "Device is an [iPad 2](https://support.apple.com/kb/SP622)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP622/SP622_01-ipad2-mul.png", ["iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4"], 9.7, (3, 4), "iPad 2", 132, False, False, False, False, False, False), - Device("iPad3", "Device is an [iPad (3rd generation)](https://support.apple.com/kb/SP647)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP662/sp662_ipad-4th-gen_color.jpg", ["iPad3,1", "iPad3,2", "iPad3,3"], 9.7, (3, 4), "iPad 3", 264, False, False, False, False, False, False), - Device("iPad4", "Device is an [iPad (4th generation)](https://support.apple.com/kb/SP662)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP662/sp662_ipad-4th-gen_color.jpg", ["iPad3,4", "iPad3,5", "iPad3,6"], 9.7, (3, 4), "iPad 4", 264, False, False, False, False, False, False), - Device("iPadAir", "Device is an [iPad Air](https://support.apple.com/kb/SP692)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP692/SP692-specs_color-mul.png", ["iPad4,1", "iPad4,2", "iPad4,3"], 9.7, (3, 4), "iPad Air", 264, False, False, False, False, False, False), - Device("iPadAir2", "Device is an [iPad Air 2](https://support.apple.com/kb/SP708)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP708/SP708-space_gray.jpeg", ["iPad5,3", "iPad5,4"], 9.7, (3, 4), "iPad Air 2", 264, False, False, False, False, True, False), - Device("iPad5", "Device is an [iPad 5](https://support.apple.com/kb/SP751)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP751/ipad_5th_generation.png", ["iPad6,11", "iPad6,12"], 9.7, (3, 4), "iPad 5", 264, False, False, False, False, True, False), - Device("iPad6", "Device is an [iPad 6](https://support.apple.com/kb/NotYetAvailable)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP751/ipad_5th_generation.png", ["iPad7,5", "iPad7,6"], 9.7, (3, 4), "iPad 6", 264, False, False, False, False, True, False), - Device("iPadAir3", "Device is an [iPad Air (3rd generation)](INSERT LINK)", "https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/image/AppleInc/aos/published/images/i/pa/ipad/mini/ipad-mini-compare-201903", ["iPad11,3", "iPad11,4"], 10.5, (3, 4), "iPad Air (3rd generation)", 264, False, False, False, False, True, False), - Device("iPadMini", "Device is an [iPad Mini](https://support.apple.com/kb/SP661)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP661/sp661_ipad_mini_color.jpg", ["iPad2,5", "iPad2,6", "iPad2,7"], 7.9, (3, 4), "iPad Mini", 163, False, True, False, False, False, False), - Device("iPadMini2", "Device is an [iPad Mini 2](https://support.apple.com/kb/SP693)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP693/SP693-specs_color-mul.png", ["iPad4,4", "iPad4,5", "iPad4,6"], 7.9, (3, 4), "iPad Mini 2", 326, False, True, False, False, False, False), - Device("iPadMini3", "Device is an [iPad Mini 3](https://support.apple.com/kb/SP709)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP709/SP709-space_gray.jpeg", ["iPad4,7", "iPad4,8", "iPad4,9"], 7.9, (3, 4), "iPad Mini 3", 326, False, True, False, False, True, False), - Device("iPadMini4", "Device is an [iPad Mini 4](https://support.apple.com/kb/SP725)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP725/SP725ipad-mini-4.png", ["iPad5,1", "iPad5,2"], 7.9, (3, 4), "iPad Mini 4", 326, False, True, False, False, True, False), - Device("iPadMini5", "Device is an [iPad Mini (5th generation)](INSERT LINK)", "https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/image/AppleInc/aos/published/images/i/pa/ipad/air/ipad-air-compare-201903", ["iPad11,1", "iPad11,2"], 7.9, (3, 4), "iPad Mini (5th generation)", 326, False, True, False, False, True, False), - Device("iPadPro9Inch", "Device is an [iPad Pro 9.7-inch](https://support.apple.com/kb/SP739)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP739/SP739.png", ["iPad6,3", "iPad6,4"], 9.7, (3, 4), "iPad Pro (9.7-inch)", 264, False, False, True, False, True, False), - Device("iPadPro12Inch", "Device is an [iPad Pro 12-inch](https://support.apple.com/kb/sp723)", "http://images.apple.com/v/ipad-pro/c/images/shared/buystrip/ipad_pro_large_2x.png", ["iPad6,7", "iPad6,8"], 12.9, (3, 4), "iPad Pro (12.9-inch)", 264, False, False, True, False, True, False), - Device("iPadPro12Inch2", "Device is an [iPad Pro 12-inch (2nd generation)](https://support.apple.com/kb/SP761)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP761/ipad-pro-12in-hero-201706.png", ["iPad7,1", "iPad7,2"], 12.9, (3, 4), "iPad Pro (12.9-inch) (2nd generation)", 264, False, False, True, False, True, False), - Device("iPadPro10Inch", "Device is an [iPad Pro 10.5-inch](https://support.apple.com/kb/SP762)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP761/ipad-pro-10in-hero-201706.png", ["iPad7,3", "iPad7,4"], 10.5, (3, 4), "iPad Pro (10.5-inch)", 264, False, False, True, False, True, False), - Device("iPadPro11Inch", "Device is an [iPad Pro 11-inch](https://support.apple.com/kb/not-published-yet)", "https://support.apple.com/not-published-yet", ["iPad8,1", "iPad8,2", "iPad8,3", "iPad8,4"], 11.0, (139, 199), "iPad Pro (11-inch)", 264, False, False, True, False, False, True), - Device("iPadPro12Inch3", "Device is an [iPad Pro 12.9-inch (3rd generation)](https://support.apple.com/kb/not-published-yet)", "https://support.apple.com/not-published-yet", ["iPad8,5", "iPad8,6", "iPad8,7", "iPad8,8"], 12.9, (512, 683), "iPad Pro (12.9-inch) (3rd generation)", 264, False, False, True, False, False, True) + Device("iPad2", "Device is an [iPad 2](https://support.apple.com/kb/SP622)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP622/SP622_01-ipad2-mul.png", ["iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4"], 9.7, (3, 4), "iPad 2", 132, False, False, False, False, False, False, False, False), + Device("iPad3", "Device is an [iPad (3rd generation)](https://support.apple.com/kb/SP647)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP662/sp662_ipad-4th-gen_color.jpg", ["iPad3,1", "iPad3,2", "iPad3,3"], 9.7, (3, 4), "iPad (3rd generation)", 264, False, False, False, False, False, False, False, False), + Device("iPad4", "Device is an [iPad (4th generation)](https://support.apple.com/kb/SP662)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP662/sp662_ipad-4th-gen_color.jpg", ["iPad3,4", "iPad3,5", "iPad3,6"], 9.7, (3, 4), "iPad (4th generation)", 264, False, False, False, False, False, False, False, False), + Device("iPadAir", "Device is an [iPad Air](https://support.apple.com/kb/SP692)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP692/SP692-specs_color-mul.png", ["iPad4,1", "iPad4,2", "iPad4,3"], 9.7, (3, 4), "iPad Air", 264, False, False, False, False, False, False, False, False), + Device("iPadAir2", "Device is an [iPad Air 2](https://support.apple.com/kb/SP708)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP708/SP708-space_gray.jpeg", ["iPad5,3", "iPad5,4"], 9.7, (3, 4), "iPad Air 2", 264, False, False, False, False, True, False, False, False), + Device("iPad5", "Device is an [iPad (5th generation)](https://support.apple.com/kb/SP751)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP751/ipad_5th_generation.png", ["iPad6,11", "iPad6,12"], 9.7, (3, 4), "iPad (5th generation)", 264, False, False, False, False, True, False, False, False), + Device("iPad6", "Device is an [iPad (6th generation)](https://support.apple.com/kb/SP774)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP751/ipad_5th_generation.png", ["iPad7,5", "iPad7,6"], 9.7, (3, 4), "iPad (6th generation)", 264, False, False, False, False, True, False, False, False), + Device("iPadAir3", "Device is an [iPad Air (3rd generation)](https://support.apple.com/kb/SP787)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP787/ipad-air-2019.jpg", ["iPad11,3", "iPad11,4"], 10.5, (3, 4), "iPad Air (3rd generation)", 264, False, False, False, False, True, False, False, False), + Device("iPadMini", "Device is an [iPad Mini](https://support.apple.com/kb/SP661)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP661/sp661_ipad_mini_color.jpg", ["iPad2,5", "iPad2,6", "iPad2,7"], 7.9, (3, 4), "iPad Mini", 163, False, True, False, False, False, False, False, False), + Device("iPadMini2", "Device is an [iPad Mini 2](https://support.apple.com/kb/SP693)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP693/SP693-specs_color-mul.png", ["iPad4,4", "iPad4,5", "iPad4,6"], 7.9, (3, 4), "iPad Mini 2", 326, False, True, False, False, False, False, False, False), + Device("iPadMini3", "Device is an [iPad Mini 3](https://support.apple.com/kb/SP709)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP709/SP709-space_gray.jpeg", ["iPad4,7", "iPad4,8", "iPad4,9"], 7.9, (3, 4), "iPad Mini 3", 326, False, True, False, False, True, False, False, False), + Device("iPadMini4", "Device is an [iPad Mini 4](https://support.apple.com/kb/SP725)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP725/SP725ipad-mini-4.png", ["iPad5,1", "iPad5,2"], 7.9, (3, 4), "iPad Mini 4", 326, False, True, False, False, True, False, False, False), + Device("iPadMini5", "Device is an [iPad Mini (5th generation)](https://support.apple.com/kb/SP788)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP788/ipad-mini-2019.jpg", ["iPad11,1", "iPad11,2"], 7.9, (3, 4), "iPad Mini (5th generation)", 326, False, True, False, False, True, False, False, False), + Device("iPadPro9Inch", "Device is an [iPad Pro 9.7-inch](https://support.apple.com/kb/SP739)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP739/SP739.png", ["iPad6,3", "iPad6,4"], 9.7, (3, 4), "iPad Pro (9.7-inch)", 264, False, False, True, False, True, False, False, False), + Device("iPadPro12Inch", "Device is an [iPad Pro 12-inch](https://support.apple.com/kb/SP723)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP723/SP723-iPad_Pro_2x.png", ["iPad6,7", "iPad6,8"], 12.9, (3, 4), "iPad Pro (12.9-inch)", 264, False, False, True, False, True, False, False, False), + Device("iPadPro12Inch2", "Device is an [iPad Pro 12-inch (2nd generation)](https://support.apple.com/kb/SP761)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP761/ipad-pro-12in-hero-201706.png", ["iPad7,1", "iPad7,2"], 12.9, (3, 4), "iPad Pro (12.9-inch) (2nd generation)", 264, False, False, True, False, True, False, False, False), + Device("iPadPro10Inch", "Device is an [iPad Pro 10.5-inch](https://support.apple.com/kb/SP762)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP761/ipad-pro-10in-hero-201706.png", ["iPad7,3", "iPad7,4"], 10.5, (3, 4), "iPad Pro (10.5-inch)", 264, False, False, True, False, True, False, False, False), + Device("iPadPro11Inch", "Device is an [iPad Pro 11-inch](https://support.apple.com/kb/SP784)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP784/ipad-pro-11-2018_2x.png", ["iPad8,1", "iPad8,2", "iPad8,3", "iPad8,4"], 11.0, (139, 199), "iPad Pro (11-inch)", 264, False, False, True, False, False, True, False, True), + Device("iPadPro12Inch3", "Device is an [iPad Pro 12.9-inch (3rd generation)](https://support.apple.com/kb/SP785)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP785/ipad-pro-12-2018_2x.png", ["iPad8,5", "iPad8,6", "iPad8,7", "iPad8,8"], 12.9, (512, 683), "iPad Pro (12.9-inch) (3rd generation)", 264, False, False, True, False, False, True, False, True) ] homePods = [ - Device("homePod", "Device is a [HomePod](https://www.apple.com/homepod/)", "https://images.apple.com/v/homepod/d/images/overview/homepod_side_dark_large_2x.jpg", ["AudioAccessory1,1"], -1, (4, 5), "HomePod", -1, False, False, False, False, False, False), + Device("homePod", "Device is a [HomePod](https://support.apple.com/kb/SP773)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP773/homepod_space_gray_large_2x.jpg", ["AudioAccessory1,1"], -1, (4, 5), "HomePod", -1, False, False, False, False, False, False, False, False), ] # tvOS tvs = [ - Device("appleTV4", "Device is an [Apple TV 4](https://support.apple.com/kb/SP724)", "http://images.apple.com/v/tv/c/images/overview/buy_tv_large_2x.jpg", ["AppleTV5,3"], 0, (), "Apple TV 4", -1, False, False, False, False, False, False), - Device("appleTV4K", "Device is an [Apple TV 4K](https://support.apple.com/kb/SP769)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP769/appletv4k.png", ["AppleTV6,2"], 0, (), "Apple TV 4K", -1, False, False, False, False, False, False) + Device("appleTV4", "Device is an [Apple TV 4](https://support.apple.com/kb/SP724)", "http://images.apple.com/v/tv/c/images/overview/buy_tv_large_2x.jpg", ["AppleTV5,3"], 0, (), "Apple TV 4", -1, False, False, False, False, False, False, False, False), + Device("appleTV4K", "Device is an [Apple TV 4K](https://support.apple.com/kb/SP769)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP769/appletv4k.png", ["AppleTV6,2"], 0, (), "Apple TV 4K", -1, False, False, False, False, False, False, False, False) ] # watchOS @@ -93,70 +95,70 @@ watches = [ "appleWatchSeries0_38mm", "Device is an [Apple Watch (1st generation)](https://support.apple.com/kb/SP735)", "https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM784/en_US/apple_watch_sport-240.png", - ["Watch1,1"], 1.5, (4,5), "Apple Watch (1st generation) 38mm", 290, False, False, False, False, False, False), + ["Watch1,1"], 1.5, (4,5), "Apple Watch (1st generation) 38mm", 290, False, False, False, False, False, False, False, False), Device( "appleWatchSeries0_42mm", "Device is an [Apple Watch (1st generation)](https://support.apple.com/kb/SP735)", "https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM784/en_US/apple_watch_sport-240.png", - ["Watch1,2"], 1.6, (4,5), "Apple Watch (1st generation) 42mm", 303, False, False, False, False, False, False), + ["Watch1,2"], 1.6, (4,5), "Apple Watch (1st generation) 42mm", 303, False, False, False, False, False, False, False, False), Device( "appleWatchSeries1_38mm", "Device is an [Apple Watch Series 1](https://support.apple.com/kb/SP745)", "https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM848/en_US/applewatch-series2-aluminum-temp-240.png", - ["Watch2,6"], 1.5, (4,5), "Apple Watch Series 1 38mm", 290, False, False, False, False, False, False), + ["Watch2,6"], 1.5, (4,5), "Apple Watch Series 1 38mm", 290, False, False, False, False, False, False, False, False), Device( "appleWatchSeries1_42mm", "Device is an [Apple Watch Series 1](https://support.apple.com/kb/SP745)", "https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM848/en_US/applewatch-series2-aluminum-temp-240.png", - ["Watch2,7"], 1.6, (4,5), "Apple Watch Series 1 42mm", 303, False, False, False, False, False, False), + ["Watch2,7"], 1.6, (4,5), "Apple Watch Series 1 42mm", 303, False, False, False, False, False, False, False, False), Device( "appleWatchSeries2_38mm", "Device is an [Apple Watch Series 2](https://support.apple.com/kb/SP746)", "https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM852/en_US/applewatch-series2-hermes-240.png", - ["Watch2,3"], 1.5, (4,5), "Apple Watch Series 2 38mm", 290, False, False, False, False, False, False), + ["Watch2,3"], 1.5, (4,5), "Apple Watch Series 2 38mm", 290, False, False, False, False, False, False, False, False), Device( "appleWatchSeries2_42mm", "Device is an [Apple Watch Series 2](https://support.apple.com/kb/SP746)", "https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM852/en_US/applewatch-series2-hermes-240.png", - ["Watch2,4"], 1.6, (4,5), "Apple Watch Series 2 42mm", 303, False, False, False, False, False, False), + ["Watch2,4"], 1.6, (4,5), "Apple Watch Series 2 42mm", 303, False, False, False, False, False, False, False, False), Device( "appleWatchSeries3_38mm", "Device is an [Apple Watch Series 3](https://support.apple.com/kb/SP766)", "https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM893/en_US/apple-watch-s3-nikeplus-240.png", - ["Watch3,1", "Watch3,3"], 1.5, (4,5), "Apple Watch Series 3 38mm", 290, False, False, False, False, False, False), + ["Watch3,1", "Watch3,3"], 1.5, (4,5), "Apple Watch Series 3 38mm", 290, False, False, False, False, False, False, False, False), Device( "appleWatchSeries3_42mm", "Device is an [Apple Watch Series 3](https://support.apple.com/kb/SP766)", "https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM893/en_US/apple-watch-s3-nikeplus-240.png", - ["Watch3,2", "Watch3,4"], 1.6, (4,5), "Apple Watch Series 3 42mm", 303, False, False, False, False, False, False), + ["Watch3,2", "Watch3,4"], 1.6, (4,5), "Apple Watch Series 3 42mm", 303, False, False, False, False, False, False, False, False), Device( "appleWatchSeries4_40mm", "Device is an [Apple Watch Series 4](https://support.apple.com/kb/SP778)", "https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM911/en_US/aw-series4-nike-240.png", - ["Watch4,1", "Watch4,3"], 1.8, (4,5), "Apple Watch Series 4 40mm", 326, False, False, False, False, False, False), + ["Watch4,1", "Watch4,3"], 1.8, (4,5), "Apple Watch Series 4 40mm", 326, False, False, False, False, False, False, False, False), Device( "appleWatchSeries4_44mm", "Device is an [Apple Watch Series 4](https://support.apple.com/kb/SP778)", "https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM911/en_US/aw-series4-nike-240.png", - ["Watch4,2", "Watch4,4"], 2.0, (4,5), "Apple Watch Series 4 44mm", 326, False, False, False, False, False, False), + ["Watch4,2", "Watch4,4"], 2.0, (4,5), "Apple Watch Series 4 44mm", 326, False, False, False, False, False, False, False, False), ] iOSDevices = iPods + iPhones + iPads + homePods @@ -176,7 +178,7 @@ import UIKit /// /// Usage: /// -/// let device = Device() +/// let device = Device.current /// /// print(device) // prints, for example, "iPhone 6 Plus" /// @@ -234,9 +236,9 @@ public enum Device { /// (e.g. "iPhone6,1" or "iPhone 6,2" do both mean "iPhone 5s")) case unknown(String) - /// Initializes a `Device` representing the current device this software runs on. - public init() { - self = Device.instance + /// Returns a `Device` representing the current device this software runs on. + public static var current: Device { + return Device.mapToDevice(identifier: Device.identifier) } /// Gets the identifier from the system, such as "iPhone7,1". @@ -252,14 +254,12 @@ public enum Device { return identifier }() - private static let instance = Device.mapToDevice(identifier: Device.identifier) - /// Maps an identifier to a Device. If the identifier can not be mapped to an existing device, `UnknownDevice(identifier)` is returned. /// /// - parameter identifier: The device identifier, e.g. "iPhone7,1". Can be obtained from `Device.identifier`. /// /// - returns: An initialized `Device`. - public static func mapToDevice(identifier: String) -> Device { // swiftlint:disable:this cyclomatic_complexity + public static func mapToDevice(identifier: String) -> Device { // swiftlint:disable:this cyclomatic_complexity function_body_length #if os(iOS) switch identifier { % for device in iOSDevices: @@ -428,14 +428,14 @@ public enum Device { public var isPhone: Bool { return (isOneOf(Device.allPhones) || isOneOf(Device.allSimulatorPhones) - || UIDevice.current.userInterfaceIdiom == .phone) && !isPod + || (UIDevice.current.userInterfaceIdiom == .phone && isCurrent)) && !isPod } /// Returns whether the device is an iPad (real or simulator) public var isPad: Bool { return isOneOf(Device.allPads) || isOneOf(Device.allSimulatorPads) - || UIDevice.current.userInterfaceIdiom == .pad + || (UIDevice.current.userInterfaceIdiom == .pad && isCurrent) } /// Returns whether the device is any of the simulator @@ -450,9 +450,10 @@ public enum Device { return Device.realDevice(from: self) } - public var isZoomed: Bool { + public var isZoomed: Bool? { + guard isCurrent else { return nil } // TODO: Longterm we need a better solution for this! - guard self != .iPhoneX && self != .iPhoneXs else { return false } + guard self != .iPhoneX && self != .iPhoneXS else { return false } if Int(UIScreen.main.scale.rounded()) == 3 { // Plus-sized return UIScreen.main.nativeScale > 2.7 @@ -486,6 +487,26 @@ public enum Device { return isTouchIDCapable || isFaceIDCapable } + /// All devices that feature a sensor housing in the screen + public static var allDevicesWithSensorHousing: [Device] { + return [${', '.join(list(map(lambda device: "." + device.caseName, list(filter(lambda device: device.hasSensorHousing == True, iOSDevices)))))}] + } + + /// Returns whether or not the device has a sensor housing + public var hasSensorHousing: Bool { + return isOneOf(Device.allDevicesWithSensorHousing) + } + + /// All devices that feature a screen with rounded corners. + public static var allDevicesWithRoundedDisplayCorners: [Device] { + return [${', '.join(list(map(lambda device: "." + device.caseName, list(filter(lambda device: device.hasRoundedDisplayCorners == True, iOSDevices)))))}] + } + + /// Returns whether or not the device has a screen with rounded corners. + public var hasRoundedDisplayCorners: Bool { + return isOneOf(Device.allDevicesWithRoundedDisplayCorners) + } + #elseif os(tvOS) /// All TVs public static var allTVs: [Device] { @@ -529,7 +550,7 @@ public enum Device { Most uses for an enum like this are the following: ``` - switch Device() { + switch Device.current { case .iPodTouch5, .iPodTouch6: callMethodOnIPods() case .iPhone4, iPhone4s, .iPhone5, .iPhone5s, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhoneSE, .iPhone8, .iPhone8Plus, .iPhoneX: callMethodOnIPhones() case .iPad2, .iPad3, .iPad4, .iPadAir, .iPadAir2, .iPadMini, .iPadMini2, .iPadMini3, .iPadMini4, .iPadPro: callMethodOnIPads() @@ -539,7 +560,7 @@ public enum Device { This code can now be replaced with ``` - let device = Device() + let device = Device.current if device.isOneOf(Device.allPods) { callMethodOnIPods() } else if device.isOneOf(Device.allPhones) { @@ -557,8 +578,14 @@ public enum Device { return devices.contains(self) } + /// Whether or not the current device is the current device. + private var isCurrent: Bool { + return self == Device.current + } + /// The name identifying the device (e.g. "Dennis' iPhone"). - public var name: String { + public var name: String? { + guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().name #else @@ -567,7 +594,8 @@ public enum Device { } /// The name of the operating system running on the device represented by the receiver (e.g. "iOS" or "tvOS"). - public var systemName: String { + public var systemName: String? { + guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().systemName #else @@ -576,7 +604,8 @@ public enum Device { } /// The current version of the operating system (e.g. 8.4 or 9.2). - public var systemVersion: String { + public var systemVersion: String? { + guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().systemVersion #else @@ -585,7 +614,8 @@ public enum Device { } /// The model of the device (e.g. "iPhone" or "iPod Touch"). - public var model: String { + public var model: String? { + guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().model #else @@ -594,7 +624,8 @@ public enum Device { } /// The model of the device as a localized string. - public var localizedModel: String { + public var localizedModel: String? { + guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().localizedModel #else @@ -726,8 +757,10 @@ extension Device { switch UIDevice.current.batteryState { case .charging: self = .charging(batteryLevel) case .full: self = .full - case .unplugged:self = .unplugged(batteryLevel) + case .unplugged: self = .unplugged(batteryLevel) case .unknown: self = .full // Should never happen since `batteryMonitoring` is enabled. + @unknown default: + self = .full // To cover any future additions for which DeviceKit might not have updated yet. } UIDevice.current.isBatteryMonitoringEnabled = wasBatteryMonitoringEnabled } @@ -740,8 +773,10 @@ extension Device { switch WKInterfaceDevice.current().batteryState { case .charging: self = .charging(batteryLevel) case .full: self = .full - case .unplugged:self = .unplugged(batteryLevel) + case .unplugged: self = .unplugged(batteryLevel) case .unknown: self = .full // Should never happen since `batteryMonitoring` is enabled. + @unknown default: + self = .full // To cover any future additions for which DeviceKit might not have updated yet. } WKInterfaceDevice.current().isBatteryMonitoringEnabled = wasBatteryMonitoringEnabled } @@ -774,12 +809,14 @@ extension Device { } /// The state of the battery - public var batteryState: BatteryState { + public var batteryState: BatteryState? { + guard isCurrent else { return nil } return BatteryState() } /// Battery level ranges from 0 (fully discharged) to 100 (100% charged). - public var batteryLevel: Int { + public var batteryLevel: Int? { + guard isCurrent else { return nil } switch BatteryState() { case .charging(let value): return value case .full: return 100 diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 9bcb811e..86a5d2c2 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -14,7 +14,7 @@ import XCTest class DeviceKitTests: XCTestCase { - let device = Device() + let device = Device.current func testDeviceSimulator() { XCTAssertTrue(device.isOneOf(Device.allSimulators)) @@ -34,6 +34,27 @@ class DeviceKitTests: XCTestCase { XCTAssertTrue(device.isSimulator) } + func testIsPhoneIsPad() { + // Test for https://github.com/devicekit/DeviceKit/issues/165 to prevent it from happening in the future. + + if UIDevice.current.userInterfaceIdiom == .pad { + XCTAssertTrue(device.isPad) + XCTAssertFalse(device.isPhone) + } else if UIDevice.current.userInterfaceIdiom == .phone { + XCTAssertFalse(device.isPad) + XCTAssertTrue(device.isPhone) + } + + for pad in Device.allPads { + XCTAssertTrue(pad.isPad) + XCTAssertFalse(pad.isPhone) + } + for phone in Device.allPhones { + XCTAssertFalse(phone.isPad) + XCTAssertTrue(phone.isPhone) + } + } + func testBattery() { XCTAssertTrue(Device.BatteryState.full > Device.BatteryState.charging(100)) XCTAssertTrue(Device.BatteryState.charging(75) != Device.BatteryState.unplugged(75)) @@ -68,10 +89,10 @@ class DeviceKitTests: XCTestCase { XCTAssertEqual(Device.mapToDevice(identifier: "iPhone10,5"), .iPhone8Plus) XCTAssertEqual(Device.mapToDevice(identifier: "iPhone10,3"), .iPhoneX) XCTAssertEqual(Device.mapToDevice(identifier: "iPhone10,6"), .iPhoneX) - XCTAssertEqual(Device.mapToDevice(identifier: "iPhone11,2"), .iPhoneXs) - XCTAssertEqual(Device.mapToDevice(identifier: "iPhone11,4"), .iPhoneXsMax) - XCTAssertEqual(Device.mapToDevice(identifier: "iPhone11,6"), .iPhoneXsMax) - XCTAssertEqual(Device.mapToDevice(identifier: "iPhone11,8"), .iPhoneXr) + XCTAssertEqual(Device.mapToDevice(identifier: "iPhone11,2"), .iPhoneXS) + XCTAssertEqual(Device.mapToDevice(identifier: "iPhone11,4"), .iPhoneXSMax) + XCTAssertEqual(Device.mapToDevice(identifier: "iPhone11,6"), .iPhoneXSMax) + XCTAssertEqual(Device.mapToDevice(identifier: "iPhone11,8"), .iPhoneXR) XCTAssertEqual(Device.mapToDevice(identifier: "iPad2,1"), .iPad2) XCTAssertEqual(Device.mapToDevice(identifier: "iPad2,2"), .iPad2) XCTAssertEqual(Device.mapToDevice(identifier: "iPad2,3"), .iPad2) @@ -136,9 +157,9 @@ class DeviceKitTests: XCTestCase { XCTAssertTrue(Device.iPhone8.screenRatio == (width: 9, height: 16)) XCTAssertTrue(Device.iPhone8Plus.screenRatio == (width: 9, height: 16)) XCTAssertTrue(Device.iPhoneX.screenRatio == (width: 9, height: 19.5)) - XCTAssertTrue(Device.iPhoneXs.screenRatio == (width: 9, height: 19.5)) - XCTAssertTrue(Device.iPhoneXsMax.screenRatio == (width: 9, height: 19.5)) - XCTAssertTrue(Device.iPhoneXr.screenRatio == (width: 9, height: 19.5)) + XCTAssertTrue(Device.iPhoneXS.screenRatio == (width: 9, height: 19.5)) + XCTAssertTrue(Device.iPhoneXSMax.screenRatio == (width: 9, height: 19.5)) + XCTAssertTrue(Device.iPhoneXR.screenRatio == (width: 9, height: 19.5)) XCTAssertTrue(Device.iPad2.screenRatio == (width: 3, height: 4)) XCTAssertTrue(Device.iPad3.screenRatio == (width: 3, height: 4)) XCTAssertTrue(Device.iPad4.screenRatio == (width: 3, height: 4)) @@ -181,9 +202,9 @@ class DeviceKitTests: XCTestCase { XCTAssertEqual(Device.iPhone7Plus.diagonal, 5.5) XCTAssertEqual(Device.iPhone8Plus.diagonal, 5.5) XCTAssertEqual(Device.iPhoneX.diagonal, 5.8) - XCTAssertEqual(Device.iPhoneXs.diagonal, 5.8) - XCTAssertEqual(Device.iPhoneXsMax.diagonal, 6.5) - XCTAssertEqual(Device.iPhoneXr.diagonal, 6.1) + XCTAssertEqual(Device.iPhoneXS.diagonal, 5.8) + XCTAssertEqual(Device.iPhoneXSMax.diagonal, 6.5) + XCTAssertEqual(Device.iPhoneXR.diagonal, 6.1) XCTAssertEqual(Device.iPad2.diagonal, 9.7) XCTAssertEqual(Device.iPad3.diagonal, 9.7) @@ -208,7 +229,7 @@ class DeviceKitTests: XCTestCase { XCTAssertEqual(Device.unknown(UUID().uuidString).diagonal, -1) } - func testDescription() { + func testDescription() { // swiftlint:disable:this function_body_length XCTAssertEqual(Device.iPodTouch5.description, "iPod Touch 5") XCTAssertEqual(Device.iPodTouch6.description, "iPod Touch 6") XCTAssertEqual(Device.iPhone4.description, "iPhone 4") @@ -226,19 +247,22 @@ class DeviceKitTests: XCTestCase { XCTAssertEqual(Device.iPhone8.description, "iPhone 8") XCTAssertEqual(Device.iPhone8Plus.description, "iPhone 8 Plus") XCTAssertEqual(Device.iPhoneX.description, "iPhone X") - XCTAssertEqual(Device.iPhoneXs.description, "iPhone Xs") - XCTAssertEqual(Device.iPhoneXsMax.description, "iPhone Xs Max") - XCTAssertEqual(Device.iPhoneXr.description, "iPhone Xr") + XCTAssertEqual(Device.iPhoneXS.description, "iPhone Xs") + XCTAssertEqual(Device.iPhoneXSMax.description, "iPhone Xs Max") + XCTAssertEqual(Device.iPhoneXR.description, "iPhone Xʀ") XCTAssertEqual(Device.iPad2.description, "iPad 2") - XCTAssertEqual(Device.iPad3.description, "iPad 3") - XCTAssertEqual(Device.iPad4.description, "iPad 4") + XCTAssertEqual(Device.iPad3.description, "iPad (3rd generation)") + XCTAssertEqual(Device.iPad4.description, "iPad (4th generation)") XCTAssertEqual(Device.iPadAir.description, "iPad Air") XCTAssertEqual(Device.iPadAir2.description, "iPad Air 2") - XCTAssertEqual(Device.iPad5.description, "iPad 5") + XCTAssertEqual(Device.iPad5.description, "iPad (5th generation)") + XCTAssertEqual(Device.iPad6.description, "iPad (6th generation)") + XCTAssertEqual(Device.iPadAir3.description, "iPad Air (3rd generation)") XCTAssertEqual(Device.iPadMini.description, "iPad Mini") XCTAssertEqual(Device.iPadMini2.description, "iPad Mini 2") XCTAssertEqual(Device.iPadMini3.description, "iPad Mini 3") XCTAssertEqual(Device.iPadMini4.description, "iPad Mini 4") + XCTAssertEqual(Device.iPadMini5.description, "iPad Mini (5th generation)") XCTAssertEqual(Device.iPadPro9Inch.description, "iPad Pro (9.7-inch)") XCTAssertEqual(Device.iPadPro12Inch.description, "iPad Pro (12.9-inch)") XCTAssertEqual(Device.iPadPro12Inch2.description, "iPad Pro (12.9-inch) (2nd generation)") @@ -276,9 +300,9 @@ class DeviceKitTests: XCTestCase { assertEqualDeviceAndSimulator(device: Device.iPhone8, property: \Device.ppi, value: 326) assertEqualDeviceAndSimulator(device: Device.iPhone8Plus, property: \Device.ppi, value: 401) assertEqualDeviceAndSimulator(device: Device.iPhoneX, property: \Device.ppi, value: 458) - assertEqualDeviceAndSimulator(device: Device.iPhoneXr, property: \Device.ppi, value: 326) - assertEqualDeviceAndSimulator(device: Device.iPhoneXs, property: \Device.ppi, value: 458) - assertEqualDeviceAndSimulator(device: Device.iPhoneXsMax, property: \Device.ppi, value: 458) + assertEqualDeviceAndSimulator(device: Device.iPhoneXR, property: \Device.ppi, value: 326) + assertEqualDeviceAndSimulator(device: Device.iPhoneXS, property: \Device.ppi, value: 458) + assertEqualDeviceAndSimulator(device: Device.iPhoneXSMax, property: \Device.ppi, value: 458) assertEqualDeviceAndSimulator(device: Device.iPad2, property: \Device.ppi, value: 132) assertEqualDeviceAndSimulator(device: Device.iPad3, property: \Device.ppi, value: 264) @@ -319,18 +343,18 @@ class DeviceKitTests: XCTestCase { } func testGuidedAccessSession() { - XCTAssertFalse(Device().isGuidedAccessSessionActive) + XCTAssertFalse(Device.current.isGuidedAccessSessionActive) } // enable once unit tests can be run on device func testKeepsBatteryMonitoringState() { UIDevice.current.isBatteryMonitoringEnabled = true XCTAssertTrue(UIDevice.current.isBatteryMonitoringEnabled) - _ = Device().batteryState + _ = Device.current.batteryState XCTAssertTrue(UIDevice.current.isBatteryMonitoringEnabled) UIDevice.current.isBatteryMonitoringEnabled = false - _ = Device().batteryState + _ = Device.current.batteryState XCTAssertFalse(UIDevice.current.isBatteryMonitoringEnabled) } @@ -365,7 +389,7 @@ class DeviceKitTests: XCTestCase { // MARK: - tvOS #if os(tvOS) func testIsSimulator() { - XCTAssertTrue(Device().isOneOf(Device.allSimulatorTVs)) + XCTAssertTrue(Device.current.isOneOf(Device.allSimulatorTVs)) } func testDescriptionFromIdentifier() {