Is it doable to test battery degree in swift whereas our software is in background?
Presently I’m engaged on one iOS (UIKit) software during which consumer can be alerted with system notification when charger is unplugged.
I attempted and this on a view controller However I need to run this code in background
UIDevice.present.isBatteryMonitoringEnabled = true
let batteryState = UIDevice.present.batteryState
change batteryState {
case .charging:
print("Charger plugged in.")
case .full:
print("Cost full")
case .unplugged:
print("Charger unplugged.")
default:
print("Battery state unknown.")
}