how to get low battery alert in iphone?
I want to display low battery alert programatically in iPhone, when battery charge level is low.
Any one have an idea about this, then please help to me. I can find ba开发者_Go百科ttery charge level by using this code
UIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];
myDevice.batteryMonitoringEnabled=YES;
float batteryLevel = [myDevice batteryLevel];
Use the battery level property from UIDevice. If the battery level is less than 5% show an alert for example. You could pool periodically for the battery level in your app delegate for example.
UIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];
float batteryLevel = [myDevice batteryLevel];
batteryLevel - The battery charge level for the device.
batteryLevel
- Battery level ranges from 0.0 (fully discharged) to 1.0 (100% charged). Before accessing this property, ensure that battery monitoring is enabled.
If battery monitoring is not enabled, battery state is UIDeviceBatteryStateUnknown
and the value of this property is –1.0.
精彩评论