I’m using CoreBluetooth to listen to advertising data to extract the bytes I need from the BLE device I have, specifically the manufacturer data.
I’ve verified my application and the code as working via Mac as a silicon app and I get the bytes as intended, however on my iPhone running the exact same code, the manufacturer data is not there, the entire key is missing.
Is there anything obvious I’ve missed? There are other apps that have this data and are able to extract it. I’ve added an image below of the BLE data from the nRF Connect app.
centralManager.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey: true])
...
if let manufacturerData = fullAdvertisementData[CBAdvertisementDataManufacturerDataKey] as? Data {
... // No bytes on iPhone so it doesn't call in here.
}
2
Answers
On iOS I discovered that iBeacons advertisement data are not available via the
CoreBluetooth
stack, they're stripped out by the framework. The correct way to get advertisement data is to useCoreLocation
, which is likely (depending on the manufacturer and device), is in theminor
andmajor
values that are broadcasted.On MacOS iBeacons and Bluetooth advertisement data remains available in
CoreBluetooth
andCoreLocation
.It looks like you’ve used Apple’s CIC (0x004C) in your Manufacturer Specific Data. You should use your own CIC. I haven’t tested this, but it would not surprise me if Apple consumes things labeled as theirs rather than passing it on to the app.
If you’re trying to advertise as an iBeacon, those generally do not appear in CoreBluetooth. They are reported by CoreLocation.