一个现代的设备检测和查询库。
使用 Xcode 11 添加 Thingy 作为包,或者更新你的 Package.swift
以进行手动设置
import PackageDescription
let package = Package(
name: "HelloWorld",
dependencies: [
.Package(url: "https://github.com/bojan/Thingy.git", "3.0.0")
]
)
将此添加到你的 Cartfile
中
github "bojan/Thingy"
将该仓库作为子模块添加到你的项目中。
git submodule add https://github.com/bojan/Thingy.git Vendor/Thingy
在 Finder 中打开新创建的文件夹,并将 Thingy.xcodeproj
拖到你的项目中。
在你的项目设置中,选择你的目标,然后在 General > Embedded Binaries 下,添加依赖于目标操作系统(iOS、watchOS 或 tvOS)的框架。
在需要的地方导入模块
import Thingy
检查当前设备
let myDevice = Device()
// Compare models or product families
if myDevice.family == .tv {
print("This is an Apple TV device.")
}
if myDevice.model != .iPhoneXSMax {
print("This is NOT an iPhone XS Max.")
}
// Pretty printed device properties
print(myDevice.family.marketingName) // e.g. iPad
print(myDevice.model.marketingName) // e.g. iPhone 7 Plus
print(myDevice.productLine.marketingName) // e.g. Air
let myDevice = Device()
do {
let result = try myDevice.isEqual(to: Thingy.iPadPro12Inch)
}
catch {
print("The devices are incompatible.")
}
do {
let result = try myDevice.isOlder(than: Thingy.iPadPro10Inch)
}
catch {
print("The devices are incompatible.")
}
let myDevice = Device()
if myDevice.display == .screen10_5Inch {
print("This is the 10.5in iPad Pro.")
}
欢迎并非常感谢所有的贡献和建议。
如果您有功能请求或您可能遇到的问题,请随时提出问题。
如果您愿意通过添加功能或修复一个或两个错误来做出贡献,请提交 pull request。
Bojan Dimovski
Thingy 在 WTFPL 许可证下可用。 查看 LICENSE 文件了解更多信息。