Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions Source/Device.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
20 changes: 20 additions & 0 deletions Source/Device.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))}]
Expand Down
17 changes: 17 additions & 0 deletions Tests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down