How to display battery status in uilabels (hours ,minutes and seconds) (03:49:33) . when battery dying decrease the time. how to check battery status
Asked
Active
Viewed 96 times
-2
-
1you can estimate using the `batteryLevel` value and the official estimation of battery's uptime on the current device, based on what progress your app is doing (e.g. video or audio-playback, etc...), what kinda services are on (e.g. wifi, bluetooth, etc...), the brightness of the screen; or just simple use the battery changes differences in a unit of time and make the estimation based on that – spoiler: none of them will be deadly accurate but it is a good estimation. – holex Apr 24 '17 at 13:12
2 Answers
0
This is how you check the battery status,
UIDevice.current.isBatteryMonitoringEnabled = true
var batteryLevel: Float {
return UIDevice.current.batteryLevel
}

harshal jadhav
- 5,456
- 2
- 18
- 26
0
UIDevice.currentDevice().batteryMonitoringEnabled = true
Then you can create a computed property to return the battery level:
var batteryLevel: Float {
return UIDevice.currentDevice().batteryLevel
}
Swift 3
UIDevice.current.isBatteryMonitoringEnabled = true
var batteryLevel: Float {
return UIDevice.current.batteryLevel
}