When developing an iOS app that monitors or transmits the battery percentage (using UIDevice.current.batteryLevel), often expect to get updates for every 1% change in battery. However, on iOS, the batteryLevel property only updates in steps of approximately 5%. For example, the value jumps from 1.0 (100%) to 0.95 (95%), then to 0.90 (90%), and so on. It does not report intermediate values like 0.99, 0.98, etc.
iOS Battery Percentage Granularity Issue
func sendBatteryInfo() { let batteryLevelRaw = UIDevice.current.batteryLevel let batteryLevel = Int((batteryLevelRaw * 100).rounded()) let state: String switch UIDevice.current.batteryState { case .charging: state = "Charging" case .full: state = "Full" case .unplugged:state = "Unplugged" default: state = "Unknown" } let message = "battery:(batteryLevel),status:(state),raw:(String(format: "%.3f", batteryLevelRaw)),temp:N/A" udpSender.send(message) batteryInfo = "Battery: (batteryLevel)% ((state))" batteryRaw = batteryLevelRaw }
This is expected and intended behavior.
please I need that we are developing a Automotive Wireless chargers I need to develop this for performance Testing any other option can you provide