部件
一个现代的设备检测和查询库。
特性
- Swift 4 支持
- 现代语法
- 文档
- 设备检测
- 设备家族检测
- 设备屏幕
- 模拟器检测
- 简单查询
要求
安装
Swift 包管理者 (SPM)
创建一个 Package.swift
文件,并添加下面的代码片段
import PackageDescription
let package = Package(
name: "HelloWorld",
dependencies: [
.Package(url: "https://github.com/bojan/Thingy.git", "2.0.2")
]
)
Carthage
将其添加到你的 Cartfile
github "bojan/Thingy"
CocoaPods
将其添加到你的 Podfile
pod '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 != .iPhone7Plus {
print("This is NOT an iPhone 7 Plus.")
}
// 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采用MIT许可证。请查看LICENSE文件以获取更多信息。