iOS Dev Nugget 180 Low Power Mode


Need to run a code review on your codebase? Hire me

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() {
        selector: #selector(lowPowerModeChanged),
        name: NSProcessInfoPowerStateDidChangeNotification,
        object: nil)

func lowPowerModeChanged(notification: NSNotification) {
    if NSProcessInfo.processInfo().lowPowerModeEnabled {
        //Do less
    } else {

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



Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter


View archives of past issues