UIDeviceModel 2.0.0

UIDeviceModel 2.0.0

theoriginalbit 维护。



  • 作者:
  • theoriginalbit

UIDeviceModel

Language License Pod Version Carthage Compatible

一个 µ 框架,通过扩展 UIDevice 提供设备模型检测。它还允许检测模拟器和正在模拟的设备模型。

安装

CocoaPods

pod 'UIDeviceModel', '~> 1.0'

Carthage

github "theoriginalbit/UIDeviceModel"

使用

首先导入框架

import UIDeviceModel

常见用法是在 switch 语句中使用

let deviceModel = UIDevice.current.deviceModel

switch deviceModel {
case .iPhone6sPlus: break // You're on an iPhone 6s Plus
case .iPhoneXS: break // You're on an iPhone XS
case .simulator: break // Oh, hello there developer!
default: break
}

如果需要,您可以将模拟器展开以获取正在模拟的设备模型

let deviceModel = UIDevice.current.deviceModel.unwrapIfSimulator

// Or as an enum

switch deviceModel {
case .simulator(let simulatedDeviceModel): break // It's as if it never happened
default: break
}