iOS 9 introduces Low Power Mode. When the user enables Low Power Mode, NSProcessInfo.processInfo().lowPowerModeEnabled
returns true
. We can observe the NSProcessInfoPowerStateDidChangeNotification
notification and check against the lowPowerModeEnabled
flag.
func someMethod() {
NSNotificationCenter.defaultCenter().addObserver(self,
selector: #selector(lowPowerModeChanged),
name: NSProcessInfoPowerStateDidChangeNotification,
object: nil)
}
func lowPowerModeChanged(notification: NSNotification) {
if NSProcessInfo.processInfo().lowPowerModeEnabled {
//Do less
} else {
//OK
}
}
When Low Power Mode is enabled, iOS switches off several system features such as background fetch and motion effects, and reduces CPU and GPU performance. As developers, we can play a part too. Switch off expensive visual effects (such as complex animations) or delay unnecessary operations that consumes significant battery such as network operations via cellular connectivity. Be a good iOS citizen app.
#181 talks more about Swift selectors.
Your feedback is valuable: Do you want more nuggets like this? Yes or No
.
.