

dependencies: [
.package(url: "https://github.com/William-Weng/WWDetectDevice.git", .upToNextMajor(from: "1.3.2"))
]
函数 |
功能 |
deviceModelObject(type:) |
取得该装置类型的全文件资料 (iPad / iPhone / AppleTV / AppleWatch) |
deviceModel(type:) |
取得该装置类型的全文件字典 (iPad / iPhone / AppleTV / AppleWatch) |
deviceIdentifier() |
取得该装置的内部编号 (实机才可以) |
deviceInformation(identifier:) |
取得该单一装置类型的信息 |
deviceType(identifier:) |
依照装置Id去解析DeviceType |
deviceEnum(identifier:) |
依照装置Id去找出Enum |
deviceSystemInformation() |
取得系统的相关信息 |
import UIKit
import WWDetectDevice
final class ViewController: UIViewController {
private typealias Info = (type: WWDetectDevice.DeviceType, identifier: String)
private let identifiers: [String] = [
"AppleTV6,2",
"iPad5,4",
"Watch6,9",
WWDetectDevice.shared.deviceIdentifier(),
]
@IBAction func detectDevice(_ sender: UIButton) {
guard let identifier = identifiers[safe: sender.tag],
let deviceEnum = WWDetectDevice.shared.deviceEnum(identifier: identifier),
let name = WWDetectDevice.shared.deviceInformation(identifier: identifier)["name"] as? String
else {
return
}
sender.setTitle(name, for: .normal)
print(deviceEnum)
}
@IBAction func detectOS(_ sender: UIButton) {
let os = "\(WWDetectDevice.shared.deviceSystemInformation().name) \(WWDetectDevice.shared.deviceSystemInformation().version)"
sender.setTitle(os, for: .normal)
}
}