Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 594
bhumika Avatar asked Jul 16 '19 05:07

bhumika


People also ask

Does iOS support classic Bluetooth?

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.

How do I request permission for Bluetooth iOS?

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.


Video Answer


1 Answers

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

like image 74
troligtvis Avatar answered Sep 28 '22 01:09

troligtvis