r/iOSProgramming • u/Ottiro2000 • 4d ago
Question How do some apps access battery details of AirPods
Title basically says everything.
I could only find a private but not public API to access battery details of AirPods in my own App.
However update submission using private APIs will be refused by Apple due to guidance 2.5.1
Does anyone know how other Apps in AppStore do it or do they maybe just use private and are lucky in review?
5
Upvotes
1
u/Sea_Wrongdoer_3500 4d ago
pretty sure most of them dont use any private api. airpods constantly broadcast ble advertisements (apple continuity "proximity pairing" messages) and battery + charging state is in there unencrypted. you just scan with CBCentralManager and parse the manufacturer data (apple company id 0x004C)
few gotchas tho. its only ~10% steps, not exact. you pick up every airpods nearby so you need some logic to figure out which ones are actually yours (rssi, model etc). and background scanning without service uuids is pretty limited so its mostly a foreground thing
format is reverse engineered and apple can change it whenever, but at least it wont get you rejected under 2.5.1
1
u/DimensionMindless336 4d ago
The "CoreBluetooth won't help" answer isn't quite right. You don't connect to the AirPods as a BLE peripheral -- you just scan their advertisements, which is public API and totally review-safe. AirPods broadcast an Apple "proximity pairing" message (company id 0x004C, so the first two bytes read 4C 00) with the battery level sitting in it unencrypted. CBCentralManager + scanForPeripherals + CBAdvertisementDataManufacturerDataKey is all you need.
The layout of that 0x07 message, since the other reply didn't spell it out: bytes 3-4 are the model id (0x0E20 = AirPods Pro, 0x1420 = Pro 2), byte 6 packs left and right bud battery into two nibbles, byte 7's upper nibble is the case and the lower nibble is charging flags. The encoding is quirky -- 0x0 to 0x9 means 0-90% in 10% steps, 0xA through 0xE all mean 100%, and 0xF means unknown/disconnected. So round to the nearest 10% in the UI, don't present it as exact.
Gotchas that actually bit me:
The system Batteries widget gets exact levels over the classic Bluetooth hands-free link via a private framework -- that's the part you can't touch without risking 2.5.1. The advert route is lower fidelity but legit.
1
u/Needle_In_Red 4d ago
pretty sure its the standard bluetooth battery service but airpods are a bit special, so some apps probaly use private stuff. not 100% tho
1
u/Dogukanko 3d ago
The 1% ones are almost certainly not using public APIs, since nothing public exposes that. Some probably just got through review because it's hard to spot. If you want to stay safe, the BLE advertisement route is the only legit option, and for picking your own pair you can filter by model and strongest RSSI while the case is open near the phone. Showing it as an approximate level is honest and won't risk your account.
1
u/Dogukanko 3d ago
The 1% ones are almost certainly not using public APIs, since nothing public exposes that. Some probably just got through review because it's hard to spot. If you want to stay safe, the BLE advertisement route is the only legit option, and for picking your own pair you can filter by model and strongest RSSI while the case is open near the phone. Showing it as an approximate level is honest and won't risk your account.
2
u/[deleted] 4d ago
[removed] — view removed comment