Is there a way to identify a BLE device in both Android and iOS

Viewed 1759

I knew how to get the mac address of a BLE device in Android by calling address from BleDevice bleDevice.address But I didn't find a way to get the UUID of the device

On the other hand in iOS I can get the UUID of a device by calling identifier from CBPeripheral peripheral.identifier But I didn't find a way to get the mac address.

Note that the mac address is not advertised in the advertisement data in iOS those are only the fields in advertisement data

kCBAdvDataIsConnectable

kCBAdvDataServiceUUIDs

kCBAdvDataTxPowerLevel

kCBAdvDataRxPrimaryPHY

kCBAdvDataLocalName

kCBAdvDataRxSecondaryPHY

kCBAdvDataTimestamp

My problem is I need an identifier that I can use in both Android and iOS to identify my ble device

2 Answers

Indeed the iOS MAC-> UUID Issue is a long standing one (and with search you'll see a number of threads on the issue).

Unfortunately there's no simple good news for a solution, and only some potential solutions... here's a summary and hope one of the paths may work for you:

iOS hides the MAC address and randomly generates a UUID for you. You can store the UUID on the phone, but it will be unique to that phone. If we both have iPhones and scan the same peripheral, we'll see different UUIDs. iOS generates the UUID on the device and hides the MAC address.

Indeed the iOS MAC-> UUID Issue is a long standing one (and with search you'll see a number of threads on the issue).

To make life easier, some devices add the some or all of the MAC address in their secondary advertising packet or in a unique device identifier in the Manufacturer data of the device and read this from the advertisement in iOS.... If you're in control of the devices firmware then I'd add this... of course if this is another party's device then you're at the mercy of their implementation.

Another possible route is using the GATT Device Information Service (Service UUID: 0x180a). Under this service there is a Serial Number String (Assigned UUID: 0x2A25) characteristic which can hold a serial number specific to the Bluetooth low energy device. But note, This is optional though and not all BLE profiles will have it, and you have to connect to the device first to retrieve this information which may not fit your usage pattern.

There may be other unique proprietary identifers for a specific device that are exposed either in advertising data or characteristics

If you're talking about an iBeacon then the advertised ibeacon guid and bluetooth address are effectively the same value.

In cases where I'm implementing the firmware for a custom BLE device I always add the 6 byte MAC address to the advertising manufacturer data. Some devices do this (or some other identifier that's not as unique like "Thermometer1020" with the 1020 hopefully being unique). But again you're at the mercy of what the device is advertising.

If you're looking for a solution that works across a wide variety of BLE devices and vendors, then unfortunatly Apple has made life difficult, if not impossible for you in their quest for security, privacy and limiting use cases of connected device applications.

In Android, BLE devices are distinguished by their hardware address. CBPeripheral.identifier property seems to be for iOS only and how their peripheral manager identifies and assigns the devices. Probably your implementation should use String as common denominator, for iOS should return identifier and for Android bleDevice.address.

Related