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的示例
| 归档时间: |
|
| 查看次数: |
3237 次 |
| 最近记录: |