UIDevice 的包装器,提供快速访问当前设备的所有必要信息。实现单例模式
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 文件。