r/reactnative • u/vegreenforlife • 11d ago
Identifying BLE devices on iOS
Building in React Native is great until you encounter platform differences.
Our app connects to training pods over BLE. The pods communicate through a JDY-24M mesh network and use the last four digits of their MAC addresses as node IDs. Android exposes the full MAC during scanning, but iOS gives you a UUID instead.
Asking the firmware for those digits on connection worked until some boards reported them incorrectly. Updating the firmware wasn’t an option. No OTA updates, and most boards are in a warehouse in China, already flashed and ready to ship.
The workaround was already in the advertising packets. The boards broadcast their full MAC. I could read their identity advertisements and associate the address with the identifier iOS provided, without changing the firmware.
The constraints pushed me toward a more robust identification process, using information the devices were already broadcasting.
Still, solving a tricky problem feels great, but avoiding it in the first place is better. Test on both platforms from day one, and keep unavoidable platform differences contained instead of scattering OS checks throughout the app.
1
10d ago
[removed] — view removed comment
1
u/vegreenforlife 10d ago
Good point about background scanning. We currently discover the pods from a dedicated scan screen, so that wasn't something I had explored.
We do keep the mapping locally, but I hadn't looked into retrievePeripheralsWithIdentifiers. I'm using react-native-ble-plx, so that's useful to know. Being able to reconnect to known pods without another scan would be useful.
Thanks for the pointers! BLE on iOS has been quite the rabbit hole.
2
u/kokerali 11d ago
Nice fix. One thing worth planning for: the UUID iOS gives you is generated per phone, so the same pod shows up with a different identifier on every iPhone. I'd keep the MAC to UUID table local to the device, never sync it or use the UUID in anything that goes to a backend, and key everything else (history, names, pairing state) by the MAC. Then a second phone or a lost table just means rebuilding the map from adverts.
If the identity frame isn't in every advertisement, you can also see a pod before you know its MAC. I'd keep it as unidentified until that frame shows up instead of falling back to the digits the firmware reports, since those are the ones you already know can be wrong. And check the manufacturer data length and layout before parsing, because in a room full of devices you'll get plenty of adverts that aren't your pods.