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()
    }()

}

Replies

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"

  • Hello @eskimo , We don't know, I cannot give you a clear answer... according to out test devices and iOSes, we saw this issue only on iPhone 8 with iOS 16. But I'm not sure that this is an iOS bug, looking in the console I can clearly see the powerd logs and the state is clearly changing, they just seems to be not forwarded to the app itself. Sorry fo the late reply forgot to subscribe to the post.

Add a Comment