diff --git a/README.md b/README.md index 10abba0f..aa09c96e 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ See our detailed [changelog](CHANGELOG.md) for the latest features, improvements - [x] Detect available sensors (Touch ID, Face ID) - [x] Detect available disk space - [x] Apple Pencil support detection +- [x] Action Button detection ## Requirements @@ -169,6 +170,14 @@ if device.isSimulator { } ``` +### Check if a device has an Action Button +```swift +let device = Device.current +if device.hasActionButton { + // Action Button specific behavior +} +``` + ### Get the Simulator Device ```swift let device = Device.current diff --git a/Source/Device.generated.swift b/Source/Device.generated.swift index bd5a0638..03a5ba25 100644 --- a/Source/Device.generated.swift +++ b/Source/Device.generated.swift @@ -1265,6 +1265,26 @@ public enum Device { return isOneOf(Device.allDevicesWithDynamicIsland) || isOneOf(Device.allDevicesWithDynamicIsland.map(Device.simulator)) } + /// All devices that have an Action Button. + public static var allDevicesWithActionButton: [Device] { + return [ + .iPhone15Pro, + .iPhone15ProMax, + .iPhone16, + .iPhone16Plus, + .iPhone16Pro, + .iPhone16ProMax, + .iPhone17, + .iPhone17Pro, + .iPhone17ProMax, + ] + } + + /// Returns whether or not the device has an Action Button. + public var hasActionButton: Bool { + return isOneOf(Device.allDevicesWithActionButton) || isOneOf(Device.allDevicesWithActionButton.map(Device.simulator)) + } + /// All devices that have 3D Touch support. public static var allDevicesWith3dTouchSupport: [Device] { return [.iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhone8, .iPhone8Plus, .iPhoneX, .iPhoneXS, .iPhoneXSMax] diff --git a/Source/Device.swift.gyb b/Source/Device.swift.gyb index 36c04251..031fff93 100644 --- a/Source/Device.swift.gyb +++ b/Source/Device.swift.gyb @@ -727,6 +727,26 @@ public enum Device { return isOneOf(Device.allDevicesWithDynamicIsland) || isOneOf(Device.allDevicesWithDynamicIsland.map(Device.simulator)) } + /// All devices that have an Action Button. + public static var allDevicesWithActionButton: [Device] { + return [ + .iPhone15Pro, + .iPhone15ProMax, + .iPhone16, + .iPhone16Plus, + .iPhone16Pro, + .iPhone16ProMax, + .iPhone17, + .iPhone17Pro, + .iPhone17ProMax, + ] + } + + /// Returns whether or not the device has an Action Button. + public var hasActionButton: Bool { + return isOneOf(Device.allDevicesWithActionButton) || isOneOf(Device.allDevicesWithActionButton.map(Device.simulator)) + } + /// All devices that have 3D Touch support. public static var allDevicesWith3dTouchSupport: [Device] { return [${', '.join(list(map(lambda device: "." + device.caseName, list(filter(lambda device: device.hasForce3dTouchSupport == True, iOSDevices)))))}] diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 1e87af88..618935d7 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -551,6 +551,23 @@ class DeviceKitTests: XCTestCase { } } + func testHasActionButton() { + let actionButtonDevices: [Device] = [ + .iPhone15Pro, + .iPhone15ProMax, + .iPhone16, + .iPhone16Plus, + .iPhone16Pro, + .iPhone16ProMax, + .iPhone17, + .iPhone17Pro, + .iPhone17ProMax, + ] + for device in Device.allRealDevices { + XCTAssertTrue(device.hasActionButton == device.isOneOf(actionButtonDevices), "testHasActionButton failed for \(device.description)") + } + } + func testHas5gSupport() { let has5gDevices: [Device] = [ .iPhone12,