How to discover Bluetooth Classic device in iOS 13 using Core bluetooth Framework

bhu*_*ika 6 bluetooth core-bluetooth swift ios13

I am trying to discover Bluetooth LE and Classic (BR/EDR) device using Core Bluetooth framework in my app which is running on iOS-13. But I am able to find only BLE devices.

How I can scan for Bluetooth Classic devices?

After initialising CBCentralManager and getting the state of CentralManager as powered on, I am scanning for peripheral devices by passing nil in Services and Options.

Code mentioned below :-

private var cbManager: CBCentralManager!

override func viewDidLoad() {
     super.viewDidLoad()
     cbManager = CBCentralManager(delegate: self, queue: nil)
}

func centralManagerDidUpdateState(_ central: CBCentralManager) {
     switch central.state {
        case .poweredOn:
             cbManager.scanForPeripherals(withServices: nil, options:nil)

        default:
             os_log("Cleaning up cbManager")
     }
}


func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {

     if let name = peripheral.name {
         print(name)
     }
}
Run Code Online (Sandbox Code Playgroud)

Through this I am only getting BLE devices. Expected result should be : BLE and Classic(BR/EDR) devices list.

小智 2

在您的内部.powerOn添加此内容以便能够匹配特定服务 UUID。

let matchingOptions = [CBConnectionEventMatchingOption.serviceUUIDs: [uuid-to-classic-bt-device]]
            cbManager.registerForConnectionEvents(options: matchingOptions)
Run Code Online (Sandbox Code Playgroud)

然后,在委托方法中,centralManager:connectionEventDidOccur:forPeripheral:您可以检查事件.peerDisconnected并对.peerConnected找到的外围设备执行某些操作。

Apple 提供了一个使用 Core Bluetooth Classic的示例

  • @sublimepremise 我发现新的 BR/EDR 支持专门用于实现 GATT 配置文件的蓝牙经典设备。在“registerForConnectionEvents”方法的matchingOptions 中提供的UUID 是GATT UUID,而不是SDP UUID。这意味着,使用 CoreBluetooth,您无法为实现 A2DP 或 HFP 配置文件的设备注册连接事件。请参阅此处/sf/ask/4101488891/ (3认同)