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?
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.
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.
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.
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#>
}
}
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#>
}
}
Yes, you can either add an observer or query it directly.
https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/LowPowerMode.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With