7

I have a problem listing all of the devices through IOBluetooth framework. Is there a way to get not only classic, but also BLE devices?

My code is

let ioBluetoothManager = IOBluetoothDeviceInquiry(delegate: self)
var ioDevices = [IOBluetoothDevice]()
...
ioBluetoothManager?.start()
...

func deviceInquiryStarted(_ sender: IOBluetoothDeviceInquiry!) {
    print("started")
}
///
//IOBluetoothDeviceInquiryDelegate
///

func deviceInquiryDeviceFound(_ sender: IOBluetoothDeviceInquiry!, device: IOBluetoothDevice!) {
    print("found device")
    ioDevices.append(device)
    scrubber.reloadData()
    tableView.reloadData()
}

func deviceInquiryComplete(_ sender: IOBluetoothDeviceInquiry!, error: IOReturn, aborted: Bool) {
    print("completed")
}

I know I can do that with CoreBluetooth, but I also need to filter devices to match a certain criteria.

From this answer I know that I can do that, but that answer lacks details. For now I'm just getting the list of classic bluetooth devices.

Could anyone please help?

UPD:

Now I found .searchType method with kIOBluetoothDeviceSearchClassic and kIOBluetoothDeviceSearchLE constants. In viewDidLoad I did the following:

ioBlutoothmanager.searchType = IOBluetoothDeviceSearchLE.rawValue but it still only finds the classic devices.

UPD:

All this time it was working so properly I didn't expect. It filtered all the devices I don't need and I didn't have AirPods to check that.

Max Kraev
  • 740
  • 12
  • 31

1 Answers1

9

Ok, so at last it's working. Just need to set the searchType property to IOBluetoothDeviceSearchLE.rawValue, and it excludes all the unnecessary devices from search – just exactly what I was looking for. Now my search query is exactly as the default Bluetooth Explorer.

ioBlutoothmanager.searchType = kIOBluetoothDeviceSearchLE.rawValue

Maybe it will help someone some day

Ted Mielczarek
  • 3,919
  • 26
  • 32
Max Kraev
  • 740
  • 12
  • 31
  • Documentation of the IOBluetooth framework is so sparse... would you care to post the complete program that you used for this? – corwin.amber Nov 01 '21 at 22:14
  • 2
    Hi, @corwin.amber, it's available on github https://github.com/havebeenfitz/touchbarconnector – Max Kraev Nov 08 '21 at 08:38