I have the same issue too.
It doesn't happen on all devices but is consistent 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 systemUptimeChanges
, isLowPowerModeEnabled
is the only state that never changes.
Tried to dispatch on main thread, but the result are the same.
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()
}()
}
Where you able to solve it?