-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expanded readme to demonstrate the new functionality
- Loading branch information
Dennis Weissmann
committed
Dec 22, 2015
1 parent
76c820b
commit 70181c4
Showing
1 changed file
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,121 @@ | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/dennisweissmann/DeviceKit/master/LICENSE) | ||
[![Build Status](https://travis-ci.org/dennisweissmann/DeviceKit.svg)](https://travis-ci.org/dennisweissmann/DeviceKit) | ||
[![CocoaPods](https://img.shields.io/cocoapods/p/Device.svg)](https://travis-ci.org/dennisweissmann/DeviceKit) | ||
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/DeviceKit.svg)](https://travis-ci.org/dennisweissmann/DeviceKit) | ||
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) | ||
[![Platform](https://img.shields.io/cocoapods/p/DeviceKit.svg?style=flat)](http://cocoadocs.org/docsets/DeviceKit) | ||
|
||
# What is this? | ||
`DeviceKit` is a value-type wrapper and extension of [`UIDevice`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/). | ||
`Device` is a value-type replacement of [`UIDevice`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/). | ||
|
||
##Features | ||
|
||
- [x] Device identification | ||
- [x] Device family detection | ||
- [x] Device group detection | ||
- [x] Simulator detection | ||
- [x] Battery state | ||
- [x] Battery level | ||
- [x] Equatable | ||
|
||
## Requirements | ||
Swift 2.0 | ||
|
||
- iOS 8.0+ / tvOS 9.0+ | ||
- Xcode 7.2+ | ||
|
||
## Installation | ||
DeviceKit can be installed in various ways. | ||
### CocoaPods | ||
|
||
```ruby | ||
source 'https://github.com/CocoaPods/Specs.git' | ||
platform :ios, '8.0' | ||
use_frameworks! | ||
|
||
pod 'DeviceKit', '~> 0.1.0' | ||
``` | ||
|
||
### Carthage | ||
|
||
```ogdl | ||
github "dennisweissmann/DeviceKit" ~> 0.1.0 | ||
``` | ||
|
||
### 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: | ||
```bash | ||
$ git submodule add https://github.com/dennisweissmann/DeviceKit.git | ||
``` | ||
|
||
## Usage | ||
Here are some usage examples. All devices are also available as simulators: | ||
```swift | ||
.iPhone6 => .Simulator(.iPhone6) | ||
.iPhone6s => .Simualtor(.iPhone6s) | ||
``` | ||
|
||
etc. | ||
|
||
### Get the Device You're Running On | ||
```swift | ||
let device = Device() | ||
|
||
print(device) // prints for example "iPhone 6 Plus" | ||
print(device) // prints, for example, "iPhone 6 Plus" | ||
|
||
if device == .iPhone6Plus { | ||
// Do something | ||
} else { | ||
// Do something else | ||
} | ||
``` | ||
|
||
... | ||
### Get the Device Family | ||
```swift | ||
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) | ||
} | ||
``` | ||
|
||
### Get the Simulator Device | ||
```swift | ||
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 | ||
```swift | ||
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 | ||
```swift | ||
if device.batteryState == .Full || device.batteryState >= .Charging(75) { | ||
print("Your battery is happy! 😊") | ||
} | ||
``` | ||
|
||
... | ||
### Get the Current Battery Level | ||
```swift | ||
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. |