I have a problem with devices using CoreBluetooth framework. Basically I need to copy the functionality of standard bluetooth discover app in OSX, so I did th following:
let bluetoothManager = CBCentralManager()
//Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
bluetoothManager.delegate = self
}
//delegate method
func centralManagerDidUpdateState(_ central: CBCentralManager) {
switch central.state {
case .poweredOn:
print("powered on")
central.scanForPeripherals(withServices: nil, options: nil)
case .unknown:
print("state unknown")
case .resetting:
print("resetting")
case .unsupported:
print("unsupported")
case .unauthorized:
print("unauthorized")
case .poweredOff:
print("powered off")
}
}
This code only discovers iphones and TVs, but ignoring the apple's keyboard and mouse. Is there something I'm missing? Maybe I need some services to define in withServices:?
For now I just print peripherals into console:
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
print("discovered some perilherials", peripheral)
}
I searched the bluetooth.com specs, but with no luck
Any advice would be nice!
Core Bluetooth can only discover BLE GATT profile devices. For legacy devices and profiles (such as the HID profile advertised by a keyboard) you will need to use the IOBluetooth framework