Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to detect iOS 9 low power mode programmatically?

I know the user can detect low power mode by observing the colour of the battery icon, but is there an API call that allows a program to detect low power mode?

like image 694
MHV Avatar asked Jun 19 '15 18:06

MHV


People also ask

How do you know if iPhone is in low power mode?

To turn Low Power Mode on or off, go to Settings > Battery. You can also turn Low Power Mode on and off from Control Centre. Go to Settings > Control Centre > Customise Controls, and then select Low Power Mode to add it to Control Centre.

How you handle low battery in your app?

To turn Battery Saver on manually, choose Battery, then Battery Saver from Android Settings. Tap Turn on now to enable the mode, or choose Set a schedule—this will let you specify what power level will trigger Battery Saver.

Does low power mode stop tracking?

We're happy to assist you. When Low Power Mode is on, it will limit some features on your iPhone to help lower the battery drain. Location services isn't one of these features. Find My will still be enabled when Low Power Mode is on.


2 Answers

Here is a code snippet to check for low power mode. Note that this feature requires iOS 9 or above. If you are not targeting an older version, you can do away with the version check.

Swift 4.2

if #available(iOS 9.0, *) {
    if ProcessInfo.processInfo.isLowPowerModeEnabled {
        <#Do low power stuff#>
    } else {
        <#Not in low power mode#>
    }
}
Doc

https://developer.apple.com/documentation/foundation/processinfo/1617047-islowpowermodeenabled

Swift 3.0

if #available(iOS 9.0, *) {
    if ProcessInfo.processInfo().lowPowerModeEnabled {
        <#Do low power stuff#>
    } else {
        <#Not in low power mode#>
    }
}

Swift 2.2

if #available(iOS 9.0, *) {
    if NSProcessInfo.processInfo().lowPowerModeEnabled {
        <#Do low power stuff#>
    } else {
        <#Not in low power mode#>
    }
}
like image 140
CodeBender Avatar answered Nov 15 '22 20:11

CodeBender


Yes, you can either add an observer or query it directly.

https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/LowPowerMode.html

like image 34
Casey Avatar answered Nov 15 '22 19:11

Casey