Giter Club home page Giter Club logo

devicekit's Introduction

GitHub license CocoaPods Compatible Carthage Compatible codecov Platform

Branch Build Status Versions
master Build Status -
Swift 4 Build Status ≥ 1.3.0
Swift 3 Build Status ≥ 1.0 ≤ 1.2.3
Swift 2.3 Build Status < 1.0

DeviceKit 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

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

github "dennisweissmann/DeviceKit" ~> 1.0

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

First make sure to import the framework:

import DeviceKit

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

.iPhone6 => .simulator(.iPhone6)
.iPhone6s => .simulator(.iPhone6s)

Get the Device You're Running On

let device = Device()

print(device)     // prints, for example, "iPhone 6 Plus"

if device == .iPhone6Plus {
  // Do something
} else {
  // Do something else
}

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)
}

Check If Running on Simulator

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

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
}

Make Sure the Device Is Contained in a Preconfigured Group

let groupOfAllowedDevices: [Device] = [.iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .simulator(.iPhone6), .simulator(.iPhone6Plus), .simulator(.iPhone6s), .simulator(.iPhone6sPlus)]
let device = 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()
}

Source of Information

All model identifiers are taken from the following website: https://www.theiphonewiki.com/wiki/Models or extracted from the simulator app bundled with Xcode.

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.

Contributors

The following people (in alphabetical order) contributed to this project - it wouldn't be what it is without you! Thank you very much! 🙏

devicekit's People

Contributors

dennisweissmann avatar piterwilson avatar kraigwastlund avatar dearprakash avatar phiren avatar walsht avatar geniejhang avatar elgordino avatar kdawgwilk avatar ruipfcosta avatar urkman avatar stevemoser avatar

Watchers

Stalin Kay avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.