开发者

how to get low battery alert in iphone?

开发者 https://www.devze.com 2023-03-16 13:04 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号