React to Low Power Mode on iPhones
Users who wish to prolong their iPhone’s battery life can enable Low Power Mode under Settings > Battery. In Low Power Mode, iOS conserves battery life by enacting certain energy-saving measures. For example, the system may:
Reduce CPU and GPU performance
Pause discretionary and background activities, including networking
Reduce screen brightness
Reduce the timeout for auto-locking the device
Disable Mail fetch
Disable motion effects
Disable animated wallpapers
The mode automatically disables when the battery level rises to a sufficient level again.
Your app should take additional steps to help the system save energy when Low Power Mode is active. For example, your app could reduce the use of animations, lower frame rates, stop location updates, disable syncs and backups, and so on.
Register for Power State Notifications
Your app can register to receive notifications when the power state (Low Power Mode is enabled or disabled) of the device changes. These notifications are posted on the global dispatch queue. See Dispatch Queues in Concurrency Programming Guide.
To register for power state notifications, send the message addObserver:selector:name:object:
to the default notification center of your app (an instance of NSNotificationCenter
). Pass it a selector to call and NSProcessInfoPowerStateDidChangeNotification
, as shown in Listing 7-1.
Once your app is notified of a power state change, it should then query isLowPowerModeEnabled
to determine the current power state. See Listing 7-2. If Low Power Mode is active, then your app can take appropriate steps to reduce activity. Otherwise, it can resume normal operations.
Objective-C
[[NSNotificationCenter defaultCenter] addObserver:self
selector: @selector(yourMethodName:)
name: NSProcessInfoPowerStateDidChangeNotification
object: nil];
Swift
NSNotificationCenter.defaultCenter().addObserver(
self,
selector: “yourMethodName:”,
name: NSProcessInfoPowerStateDidChangeNotification,
object: nil
)
Determine the Power State
Your app can query the current power state at any time by accessing the isLowPowerModeEnabled
property of the NSProcessInfo
class, as shown in Listing 7-2. This property contains a boolean value, indicating whether Low Power Mode is enabled or disabled.
Objective-C
if ([[NSProcessInfo processInfo] isLowPowerModeEnabled]) {
// Low Power Mode is enabled. Start reducing activity to conserve energy.
} else {
// Low Power Mode is not enabled.
};
Swift
if NSProcessInfo.processInfo().lowPowerModeEnabled {
// Low Power Mode is enabled. Start reducing activity to conserve energy.
} else {
// Low Power Mode is not enabled.
}
Copyright © 2018 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2016-09-13