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)
}
}
Through this I am only getting BLE devices. Expected result should be : BLE and Classic(BR/EDR) devices list.
iOS does not have a general API for talking to classic Bluetooth devices. For devices built under the aegis of MFi you can use the External Accessory framework, but that won't help for non-MFi devices. Bluetooth versions are not a good way to determine what Bluetooth features a device supports.
There is no method you can call to request authorization for bluetooth. You just have to include it in info. plist file. The system automatically displays a request for user authorization when your app first attempts to use Bluetooth services to share data.
Inside your .powerOn
add this to be able to match on a specific service UUID.
let matchingOptions = [CBConnectionEventMatchingOption.serviceUUIDs: [uuid-to-classic-bt-device]]
cbManager.registerForConnectionEvents(options: matchingOptions)
Then in the delegate method centralManager:connectionEventDidOccur:forPeripheral:
you can check for the events .peerDisconnected
and .peerConnected
to do something with the peripheral you found.
Apple provides an example of this Using Core Bluetooth Classic
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