iPhone: Get warning when battery power is very low

Solutions Collect From Internet About “iPhone: Get warning when battery power is very low”

You could use the battery level property from UIDevice. If the battery level is less than 5% show an alert for example. You could poll periodically for the battery level in your app delegate for example.

UIDevice *myDevice = [UIDevice currentDevice]; 
[myDevice setBatteryMonitoringEnabled:YES]; 
float batteryLevel = [myDevice batteryLevel];

Explanation from the docs:

The battery charge level for the device. (read-only)

@property(nonatomic, readonly) float 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.

Available in iOS 3.0 and later.

See Also
@property batteryState
@property batteryMonitoringEnabled

Declared In