Latest 0.8.1
Homepage https://github.com/RockerHX/Devices
License MIT
Platforms ios 9.0, osx 10.11, tvos 9.0, watchos 2.0
Authors

Devices

Version
Swift4.0
Swift4.1
Swift4.2
Xcode
Platform
Supported
License

Branch Build Status Versions
master Build Status
Swift 4.2 Build Status ≥ 0.8.0
Below Swift 4.2 Build Status < 0.7.2

Features

  • [x] Device identification
  • [x] Device family detection
  • [x] Device model detection
  • [x] Device size detection
  • [x] Device group detection
  • [x] Simulator detection
  • [x] Brightness detection
  • [x] Battery detection
  • [x] Equatable

Installation

CocoaPods

Devices is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "Devices"

Usage

First make sure to import the framework:

import Devices

iOS

Device family

Simple code:

func iOSDeviceFamily() {
    let family = Device.family()
    switch family {
    case .iPhone:
        print("Device belong to (family) family")
    case .unknown:
        print("unknown Device.")
    }
}

Demo code:
Family Demo Code

Device model

Simple code:

func iOSDeviceModel() {
    let model = Device.model()
    print(model.identifier)
    switch model {
    /*** iPod ***/
    case .iPodTouch6Gen:
        print("Device is a (model)")
    /*** iPhone ***/
    case .iPhoneX:
        print("Device is a (model)")
    /*** iPad ***/
    case .iPadPro10_5Inch:
        print("Device is a (model)")
    /*** HomePod ***/
    case .HomePod:
        print("Device is a (model)")
    case .simulator(.iPhoneX):
        print("Device is a (model)")
    /*** unknown ***/
    case .unknown:
        print("unknown Device.")
    }
}

Demo code:
Model Demo Code

Device screen size

Simple code:

func iOSDeviceSize() {
    let size = Device.size()
    switch size {
    case .screen12_9Inch:
        print("Device size: (size.description)")
    case .unknown:
        print("Device size unknown.")
    }
}

Demo code:
Size Demo Code

Helpers

Model

Simple code:

func iOSModelHelper() {
    let model = Device.model()
    let allPhones = Device.Model.allPhones
    if allPhones.contains(model) {
        print("Current device belong to iPhone ")
    }
    let allSimulatorPhones = Device.Model.allSimulatorPhones
    if allSimulatorPhones.contains(model) {
        print("Current device belong to iPhone Simulator")
    }
}

Demo code:
Model Helper Demo Code

Size

You can use operator like >, <, >=, <=, ==, !=

Simple code:

func iOSSizeHelper() {
    let size = Device.size()
    if size > .screen4_7Inch {
        print("Your device screen is larger than 4.7 inch")
    }

    if Device.isRetina() {
        print("It's a retina display")
    }
}

Demo code:
Size Helper Demo Code

Brightness

Apple not provide api to get brightness on tvOS and watchOS, and if you want change watchOS’s device brightness will be rejected.
So, brightness api can only support iOS and OSX platform.
iOS Simple code:

func iOSBrightness() {
    print("Device.brightness: (Device.brightness)")
    Device.brightness = 0.8
}

OSX Simple code:

func OSXBrightness() {
    print("Device.Brightness.level: (Device.Brightness.level)")
    Device.Brightness.level = .level_5
    Device.Brightness.level = .custom(0.5)
}

Battery

iOS Simple code:

func iOSBattery() {
    print(Device.Battery.state)
    let batteryState = Device.Battery.state

    switch batteryState {
    case .full:
        print("Your battery is happy! 😊")
    case .charging(let level):
        print("Your battery level: (level)")
    case .unplugged(let level):
        print("Your battery level: (level)")
    }

    if Device.Battery.lowPowerMode {
        print("Low Power mode is enabled! 🔋")
    } else {
        print("Low Power mode is disabled! 😊")
    }

    guard batteryState < .charging(80) else {
        print("Your battery is happy! 😊")
        return
    }
}

Project

iOS Simple code:

func iOSApplication() {
    print("Build: (Device.Application.shared.build)")
    print("Version: (Device.Application.shared.version)")
    print("Name: (Device.Application.shared.name)")
    print("wholeVersion: (Device.Application.shared.wholeVersion)")
    print("firstLanuch: (Device.Application.shared.firstLanuch)")
}

OSX

OSX Demo Code

tvOS

tvOS Demo Code

watchOS

watchOS Demo Code

License

Device is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Devices",
    "version": "0.8.1",
    "summary": "Devices can detect the current uf8ff device base system information. Support iOS, OSX, tvOS, watchOS.",
    "description": "This library is written in Swift 4 and compatible with > iOS 9. Devices lib take device information which you need.",
    "homepage": "https://github.com/RockerHX/Devices",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "RockerHX": "[email protected]"
    },
    "platforms": {
        "ios": "9.0",
        "osx": "10.11",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "swift_version": "4.0",
    "source": {
        "git": "https://github.com/RockerHX/Devices.git",
        "tag": "0.8.1"
    },
    "source_files": [
        "Classes",
        "Classes/*"
    ],
    "ios": {
        "frameworks": "UIKit"
    },
    "osx": {
        "frameworks": "Cocoa"
    },
    "tvos": {
        "frameworks": "UIKit"
    },
    "watchos": {
        "frameworks": "WatchKit"
    }
}

Pin It on Pinterest

Share This