ProcessInfo isLowPowerMode never changes during the same app session regarding the settings

I'm experiencing that issue but not on all devices, right now we are able to see a consistent behavior on iPhone 8 with iOS 16.7.5. The NSProcessInfoPowerStateDidChange is never called and the state is never updated during the same app session, it keeps returning the same value.

Most weird the systemUptime changes, isLowPowerModeEnabled is the only state that never changes. Tried different approach even polling but the result is always the same. the problem doesn't seems to be in the code, even DataDog SDK (integrated in the same app), that asks the isLowPowerModeEnabled to understand if it could upload logs is affetcted by the same issue.

protocol SystemPowerInfoProvider {
    var isLowPowerModeEnabled: AnyPublisher<Bool, Never> { get }
}

final class DefaultSystemBatteryOptimizationStateProvider: SystemPowerInfoProvider {
    var isLowPowerModeEnabled: AnyPublisher<Bool, Never> {
        _isLowPowerModeEnabled
    }
    
    private lazy var _isLowPowerModeEnabled: AnyPublisher<Bool, Never> =  {
        
        return Just(ProcessInfo.processInfo.isLowPowerModeEnabled)
            .merge(with: NotificationCenter.default
                .publisher(for: Notification.Name.NSProcessInfoPowerStateDidChange)
                .map { notification -> Bool? in
                    guard let processInfo = notification.object as? ProcessInfo else {
                        return nil
                    }
                    return processInfo.isLowPowerModeEnabled
                }
                .compactMap { $0 }
            )
            .eraseToAnyPublisher()
    }()

}

right now we are able to see a consistent behavior on iPhone 8 with iOS 16.7.5.

So the same code works on iOS 17?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

ProcessInfo isLowPowerMode never changes during the same app session regarding the settings
 
 
Q