Device is a value-type replacement of UIDevice.

Features

  • Device identification
  • Device family detection
  • Device group detection
  • Simulator detection
  • Battery state
  • Battery level
  • Equatable

Installation

DeviceKit can be installed in various ways.

Swift, 3.0

Pod 'DeviceKit', '~ > 1.0'Copy the code

Carthage

Swift 2.3 (Unsupported)

Making "dennisweissmann/DeviceKit" "swift - 2.3 - unsupported"Copy the code

Usage

Here are some usage examples. All devices are also available as simulators:

.iPhone6 => .Simulator(.iPhone6)
.iPhone6s => .Simualtor(.iPhone6s)Copy the code

etc.

Get the Device Family

let device = Device()
if device.isPod {
    // iPods (real or simulator)
} else if device.isPhone {
   // iPhone (real or simulator)
} else if device.isPad {
   // iPad (real or simulator)
}Copy the code

Get the Simulator Device

let device = Device()
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
default: break
}Copy the code

Get the Current Battery State

if device.batteryState == .Full || device.batteryState >= .Charging(75) {
    print("Your battery is happy! 😊")
}Copy the code

Contributing

If you have the need for a specific feature that you want implemented or if you experienced a bug, please open an issue. If you extended the functionality of DeviceKit yourself and want others to use it too, please submit a pull request.