最后更新:2019年4月6日。
如果您喜欢这个项目,请给它一个星 ⭐ 这将向创建者展示您的认可,并帮助他人发现此代码库。
✍️ 关于
🏗 安装
CocoaPods
device-kit
可通过CocoaPods
获取
pod 'device-kit', '~> 1.1.1'
手动
您始终可以使用复制粘贴源代码的方法
📚 功能
- 设备类型信息
- 轻松获取设备的
标识符
- 确定一个应用是在模拟器上运行还是在实际的设备上运行
- 包含有关每个iOS设备的详细信息
- 轻松获取设备的
- 设备存储状态,例如:
总空间
空闲
空间已用
空间- 您可以使用各种
单位
(通过使用ByteCountFormatter.Units
)来格式化数据
- 设备方向信息
- 无需调用示例代码
UIDevice.current.orientation
或进行if/else
检查,即可检查设备是否处于.portrait
或.landscape
方向 - 如果您愿意,可以使用
isPortrait
属性
- 无需调用示例代码
- 设备互联网连接状态
- 轻松检查您的设备是否已连接到互联网
- 您还可以获取可达性状态
✈️ 用途
获取设备的标识符
let identifiers = UIDevice.current.deviceType
// `identifiers` will hold the corresponding devices' identifiers depending on your `iOS` model
确定剩余多少存储空间
UIDevice.current.storageStatus.getFreeSpace(.useMB)
// Will print something like this:
// 139,197.3 MB
UIDevice.current.storageStatus.getFreeSpace(.useGB)
// Or you can change the unit type to Gigabytes:
// 139.16 GB
UIDevice.current.storageStatus.getFreeSpace(.useGB, includeUnitPostfix: false)
// If you don't want to get GB, MB postfixes then specify an optional parameter for `includeUnitPostfix`:
// 139.16
检查设备的方向
let orienation = UIDevice.current.deviceOrientation
switch orientation {
case .portrait:
showDrawerView()
case .landscape:
hideDrawerView()
}
获取互联网连接状态
let internet = UIDevice.current.internetConnection
guard internet.connection == .open else {
throw NetworkError.isNotAvailabe("Missing internet connection")
}
sendRequest()
📝 待办事项
- 轻量级
Network
可达性(带有NotificationCenter
支持或更安全的更改观察方法)-
NotificationCenter
观察者支持
-
- 设备
方向
-
NotificationCenter
观察者支持
-
- 界面
方向
-
NotificationCenter
观察者支持
-
🙋♀️ 🙋♂️ 贡献
- 对于贡献者来说,只有一条主要规则 - 请将您的扩展放在独立的文件中。这是因为此类扩展可以更容易地被引用和重用。
- 另一条软性规则是 - 请与您的扩展一起包含
单元测试
。
👨💻 作者
🔖 许可
该项目在MIT许可证下提供