DSDeviceKit 0.1.2

DSDeviceKit 0.1.2

测试已测试
语言语言 SwiftSwift
许可 MIT
发布最新发布2016年7月
SPM支持 SPM

Dmitry Sokolov 维护。




  • Dmitry Sokolov

DSDeviceKit

概述

UIDevice 的包装器,提供快速访问当前设备的所有必要信息。实现单例模式

需求

  • ARC
  • iOS 8 (动态框架)

安装

DSDeviceKit 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到 Podfile 中

pod "DSDeviceKit"

用法

import DSDeviceKit

let device = DSDeviceKit.currentDevice

print(device.modelName)     // "iPhone 6s" or "iPad Air 2" and so on
print(device.identifier)    // "iPhone8,1" or "Simulator" and so on
print(device.iOSVersion)    // "9.3" and so on
print(device.deviceType)    // "iPhone" or "iPad" or "iPod Touch" or "Unknown"
print(device.isPhone)       // true or false

let devices = ["iphone 6", "ipad pro", "iPhone SE"]


if device.isOneOf(devices) {
    // is one of the allowed devices
}


if device.deviceType == .iPodTouch { // or .iPhone or .iPad
    // ...
}

// or you can use convenient computed variables:

if device.isPhone {
    // this is iPhone
}


if device.isIPad {
    // this is iPad
}

示例项目

要运行示例项目,首先克隆仓库,然后在 Example 目录中运行 pod install

作者

Dmitry Sokolov

许可

DSDeviceKit 可在 MIT 许可下获取。有关更多信息,请参阅 LICENSE 文件。