"UIDevice.current.batteryLevel" is always "0" in macOS Sonoma 14.4

I recently updated to macOS Sonoma 14.4 and now UIDevice.current.batteryLevel is always 0.

Code to reproduce:

import SwiftUI

struct ContentView: View {
    @State
    private var monitoringEnabled = UIDevice.current.isBatteryMonitoringEnabled;
    
    @State
    private var batteryLevel = UIDevice.current.batteryLevel;
    
    var body: some View {
        VStack {
            Text("Battery Monitoring Enabled: " + String(monitoringEnabled))
            Text("Battery Level: " + String(batteryLevel))
            Button("Toggle Monitoring") {
                monitoringEnabled = !monitoringEnabled;
                
                UIDevice.current.isBatteryMonitoringEnabled = monitoringEnabled;
                batteryLevel = UIDevice.current.batteryLevel;
            }
        }
        .padding()
    }
}

Run the above on a macOS 14.4 target, click "Toggle Monitoring", and you'll see battery level is reported as 0:

I also see the following error in my app logs when running on macOS 14.4:

Error retrieving battery status: result=-536870207 percent=0 hasExternalConnected=1 isCharging=0 isFullyCharged=0

This code displays the expected battery level when running on an actual iOS device:

I'm having the same issue! Also reporting the following in the console (not sure if it's related):

CLIENT ERROR: TUINSRemoteViewController does not override -viewServiceDidTerminateWithError: and thus cannot react to catastrophic errors beyond logging them

I'm seeing the same messages in macOS Sonoma 14.5. Wondering what is causing it as the battery level is getting fetched properly and the message is triggered when plugging/unplugging the device.

"UIDevice.current.batteryLevel" is always "0" in macOS Sonoma 14.4
 
 
Q