I want to display the battery status of my device in iOS.
I am writing the following code to display the battery status.
UIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];
double batLeft = (float)[myDevice batteryLevel] * 100;
NSLog(@"%.f",batLeft);
NSString * levelLabel = [NSString stringWithFormat:@"%.f%%", batLeft];
lblLabel.text =levelLabel;
It displays battery status fine when app runs. But, when the app is in background it didn't take the updated value. I want to display the battery status what the device has at every time. I also want to fire a notification when battery was dying between 2 to 3%.