2022-08-14 22:36:22 +05:30
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct Power {
|
|
|
|
static var hasInternalBattery: Bool {
|
|
|
|
let psInfo = IOPSCopyPowerSourcesInfo().takeRetainedValue()
|
|
|
|
let psList = IOPSCopyPowerSourcesList(psInfo).takeRetainedValue() as [CFTypeRef]
|
|
|
|
|
|
|
|
for ps in psList {
|
|
|
|
if let psDesc = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? [String: Any] {
|
2022-08-15 03:50:27 +05:30
|
|
|
if let type = psDesc[kIOPSTypeKey] as? String,
|
|
|
|
type == kIOPSInternalBatteryType
|
|
|
|
{
|
|
|
|
return true
|
2022-08-14 22:36:22 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
static var isConnectedToPower: Bool {
|
|
|
|
let psInfo = IOPSCopyPowerSourcesInfo().takeRetainedValue()
|
|
|
|
let psList = IOPSCopyPowerSourcesList(psInfo).takeRetainedValue() as [CFTypeRef]
|
|
|
|
|
|
|
|
for ps in psList {
|
|
|
|
if let psDesc = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? [String: Any] {
|
|
|
|
if let type = psDesc[kIOPSTypeKey] as? String,
|
2022-08-15 03:50:27 +05:30
|
|
|
type == kIOPSInternalBatteryType,
|
2022-08-14 22:36:22 +05:30
|
|
|
let powerSourceState = (psDesc[kIOPSPowerSourceStateKey] as? String)
|
|
|
|
{
|
|
|
|
return powerSourceState == kIOPSACPowerValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|