Branch | Build Status | Versions |
---|---|---|
master | - | |
Swift 5.2 | ≥ 1.1.0 | |
Swift 5.0 | ≥ 1.0.0 | |
Swift 4.2 | ≥ 0.8.0 | |
Below Swift 4.2 | < 0.7.2 |
- Device identification
- Device family detection
- Device model detection
- Device size detection
- Device group detection
- Simulator detection
- Brightness detection
- Battery detection
- Equatable
Devices is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Devices"
First make sure to import the framework:
import Devices
Simple code:
func iOSDeviceFamily() {
let family = Device.family()
switch family {
case .iPhone:
print("Device belong to \(family) family")
case .unknown:
print("unknown Device.")
}
}
if Device.isFringe {
code...
}
Demo code: Family Demo Code
Simple code:
func iOSDeviceModel() {
let model = Device.model()
print(model.identifier)
switch model {
/*** iPod ***/
case .iPodTouch6Gen:
print("Device is a \(model)")
/*** iPhone ***/
case .iPhoneX:
print("Device is a \(model)")
/*** iPad ***/
case .iPadPro10_5Inch:
print("Device is a \(model)")
/*** HomePod ***/
case .HomePod:
print("Device is a \(model)")
case .simulator(.iPhoneX):
print("Device is a \(model)")
/*** unknown ***/
case .unknown:
print("unknown Device.")
}
}
Demo code: Model Demo Code
Simple code:
func iOSDeviceSize() {
let size = Device.size()
switch size {
case .screen12_9Inch:
print("Device size: \(size.description)")
case .unknown:
print("Device size unknown.")
}
}
Demo code: Size Demo Code
Simple code:
func iOSModelHelper() {
let model = Device.model()
let allPhones = Device.Model.allPhones
if allPhones.contains(model) {
print("Current device belong to iPhone ")
}
let allSimulatorPhones = Device.Model.allSimulatorPhones
if allSimulatorPhones.contains(model) {
print("Current device belong to iPhone Simulator")
}
}
Demo code: Model Helper Demo Code
You can use operator like >
, <
, >=
, <=
, ==
, !=
Simple code:
func iOSSizeHelper() {
let size = Device.size()
if size > .screen4_7Inch {
print("Your device screen is larger than 4.7 inch")
}
if Device.isRetina() {
print("It's a retina display")
}
}
Demo code: Size Helper Demo Code
Apple not provide api to get brightness on tvOS and watchOS, and if you want change watchOS's device brightness will be rejected. So, brightness api can only support iOS and OSX platform. iOS Simple code:
func iOSBrightness() {
print("Device.brightness: \(Device.brightness)")
Device.brightness = 0.8
}
OSX Simple code:
func OSXBrightness() {
print("Device.Brightness.level: \(Device.Brightness.level)")
Device.Brightness.level = .level_5
Device.Brightness.level = .custom(0.5)
}
iOS Simple code:
func iOSBattery() {
print(Device.Battery.state)
let batteryState = Device.Battery.state
switch batteryState {
case .full:
print("Your battery is happy! 😊")
case .charging(let level):
print("Your battery level: \(level)")
case .unplugged(let level):
print("Your battery level: \(level)")
}
if Device.Battery.lowPowerMode {
print("Low Power mode is enabled! 🔋")
} else {
print("Low Power mode is disabled! 😊")
}
guard batteryState < .charging(80) else {
print("Your battery is happy! 😊")
return
}
}
iOS Simple code:
func iOSApplication() {
print("Device is Fringe:\(Device.isFringe)")
print("Build: \(Device.Application.shared.build)")
print("Version: \(Device.Application.shared.version)")
print("Name: \(Device.Application.shared.name)")
print("wholeVersion: \(Device.Application.shared.wholeVersion)")
print("firstLanuch: \(Device.Application.shared.firstLanuch)")
}
Device is available under the MIT license. See the LICENSE file for more info.