Skip to content

Repository files navigation

GitHub licenseBuild StatusCocoaPods CompatibleCarthage CompatiblePlatform

Device is a value-type replacement of UIDevice.

##Features

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

Requirements

  • iOS 8.0+ / tvOS 9.0+ (linking against iOS 9.3 and tvOS 9.2 required)
  • Xcode 8.0+

Installation

DeviceKit can be installed in various ways.

CocoaPods

Swift 3.0

pod'DeviceKit','~> 1.0'

Swift 2.3 (Unsupported)

pod'DeviceKit',:git=>'https://github.com/dennisweissmann/DeviceKit.git',:branch=>'swift-2.3-unsupported'

Carthage

Swift 3.0

github "dennisweissmann/DeviceKit" "HEAD"

Swift 2.3 (Unsupported)

github "dennisweissmann/DeviceKit" "swift-2.3-unsupported"

Manually

To install it manually drag the DeviceKit project into your app project in Xcode or add it as a git submodule. In your project folder enter:

$ git submodule add https://github.com/dennisweissmann/DeviceKit.git

Usage

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

.iPhone6 =>.Simulator(.iPhone6).iPhone6s =>.Simualtor(.iPhone6s)

etc.

Get the Device You're Running On

letdevice=Device()print(device) // prints, for example, "iPhone 6 Plus"
if device ==.iPhone6Plus {
// Do something
}else{
// Do something else
}

Get the Device Family

letdevice=Device()if device.isPod {
// iPods (real or simulator)
}elseif device.isPhone {
// iPhone (real or simulator)
}elseif device.isPad {
// iPad (real or simulator)
}

To check if running on Simulator

letdevice=Device()if device.isSimulator {
// Running on one of the simulators(iPod/iPhone/iPad) // Skip doing something irrelevant for Simulator
}

Get the Simulator Device

letdevice=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}

Make Sure the Device Is Contained in a Preconfigured Group

letgroupOfAllowedDevices:[Device]=[.iPhone6,.iPhone6Plus,.iPhone6s,.iPhone6sPlus,.Simulator(.iPhone6),.Simulator(.iPhone6Plus),.Simulator(.iPhone6s),.Simulator(.iPhone6sPlus)]letdevice=Device()if device.isOneOf(groupOfAllowedDevices){
// Do you action
}

Get the Current Battery State

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

Get the Current Battery Level

if device.batteryLevel >=50{install_iOS()}else{showError()}

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.

About

DeviceKit is a value-type replacement of UIDevice.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages