Search code examples
iosbatterymanager

how to fetch battery status with hours,minutes and seconds in IOS?


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


Solution

  • 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
    }