iPhone: Get warning when battery power is very low
I want to know how can i get warning in my app delegate when the device battery power is very low. So that i can pause the running game.
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
UIDeviceBatteryStateUnknownand the value of this property is –1.0.
Available in iOS 3.0 and later.
- Why doesn’t iOS 5.0 like plain window applications? Why does it request that view controllers be used?
- UITableViewCell Set selected initially
- Crashlytics iOS – log caught exception
- Display two array values in single tableview cell
- If statement checking for NSString equality using ==
- Core Data Query Multiple Columns with Single Search String
- Compiler error “expected method not found” when using subscript on NSArray
- How to send in-app announcements to people using my iOS app?
- Game Center URL scheme
- UIPageViewController page control background color
- FBSDKLoginManager logInWithReadPermissions: fromViewController: handler: completion not called on app first run
- Do I have to register a new Bundle ID to upload new application to iTune Connect?
- Swift / UIView / drawrect – how to get drawrect to update when required
- Invalid Swift Support / The SwiftSupport folder is empty
- Getting description like NSObject