UPDATE: please, keep in mind that since iOS 13, CoreBluetooth now supports both BLE and classic Bluetooth devices.
From Apple:
This year, we've merged the two layers together, and now, you have transparent access to both BR/EDR and low energy without doing anything. Now, what this means for you is without much changes in the API, you can now work with both the classic devices and the low energy devices. [...] This now will allow transparent use of GATT with the BR/EDR devices. It's still running the exact same Bluetooth SIG protocol. There's no changes to that, and so you can look at this specification online on the Bluetooth SIG website. To your application and to the developer, the CBPeripheral APIs are exactly the same. You can still do the same service discovery and be notified of changes to characteristics.
Note: BR/EDR refers to the radio technology of the Bluetooth specification before the 4.0, used for LE devices. More info here.
I am trying to scan for some Bluetooth devices using CoreBluetooth but I am having trouble to discover them.
I am using Apple's sample code from this talk as reference.
This is how the Central Manager is initialized:
let cbManager = CBCentralManager(delegate: self, queue: nil)
This is how I'm scanning for peripherals:
cbManager.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey: true])
Since I don't know the serviceUUID
to which I should connect initially, I am scanning with nil as the list of CBUUID
.
When peripherals are discovered, then I get notified via the centralManager(_:didDiscover:advertisementData:rssi:)
method of the CBCentralManagerDelegate
and I hold on to those peripherals, which allows me to discover services on them via the peripheral(_:didDiscoverServices:)
method of the CBPeripheralDelegate
.
Having discovered a peripheral, and having discovered its services, I can connect directly to that peripheral next time with:
cbManager.scanForPeripherals(withServices: [myDiscoveredService], options: nil)
So far, so good.
However, I can't even seem to get started with devices which are not discovered. This is happening for a number of devices that do show up in the Bluetooth settings app.
How can I get exposed to those devices, which are clearly visible to the device but I can't get to discover from the code?
Would it help if I knew the serviceUUID to begin with? How can I get such serviceUUID by other means, possibly with additional tools?
Things I tried that did not work:
use the Bluetooth explorer from the new Xcode 11 additional tools to get information about the device: though I can get a fair amount of information about the target Bluetooth devices (via "Show Device Discovery", then "Get device info..."), I can't seem to find a suitable service UUID
use the Packet Logger for live capture of the iOS trace while scanning (from the same additional tools package): I see HCI Packets and HCI Events but I can't seem to figure out any valuable information from that traffic
I'm using iOS 13.2 and Xcode 11.2
Make sure that your Bluetooth accessory and iOS or iPadOS device are close to each other. Turn your Bluetooth accessory off and back on again. Make sure that your Bluetooth accessory is on and fully charged or connected to power. If your accessory uses batteries, see if they need to be replaced.
CoreBluetooth now supports both BLE and classic Bluetooth devices.
This is a misunderstanding of the new features. As the quoted text notes, "This now will allow transparent use of GATT with the BR/EDR devices." (emphasis added)
GATT over BR/EDR is not a particularly common feature in Bluetooth devices, and has nothing to do with audio streaming devices. Other profiles such as A2DP, HID, and HFP, are still not supported by Core Bluetooth. These are likely the profiles supported by the devices you're working with.
For those of us who design Bluetooth products, this new feature is really quite powerful and exciting, but we need to update our firmware to support it. It's not something you get for free on the hardware side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With