How to check the battery level of your iOS device?

We can use the batteryLevel property of the UIDevice class for this. It will return a float:

float myFloat = [[UIDevice currentDevice] batteryLevel];

If you’d like to print this in a UILabel you’ll have to convert it into a String Object like so:

self.myLabel.text = [NSString stringWithFormat:@"%f", myFloat];

For this to work battery monitoring needs to be enabled, perhaps in the viewDidLoad method. Otherwise the returned value will be -1.0:

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; 





Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.