Is there any way to detect iOS 9 low power mode programmatically?
Yes, you can either add an observer or query it directly.
https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/LowPowerMode.html
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#>
}
}