Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve all connected bluetooth peripherals

I am trying to get a list of all connected Peripherals to an iPhone. I have a Bose Soundlink connected but it doesn't show up in my app. I don't know the UUID so am passing [] as this should get all I think?

func centralManagerDidUpdateState(_ central: CBCentralManager) {
    var message = ""

    switch central.state {
      case .poweredOn:
         message = "Bluetooth LE is turned on and ready for communication."

         // scan for ALL devices
        centralManager.scanForPeripherals(withServices: nil, options: nil)

         let connectedPeripherals = self.centralManager.retrieveConnectedPeripherals(withServices: []) 
        // WILL [] RETURN ALL CONNECTED PERIPHERALS?
        print("connectedPeripherals are \(connectedPeripherals)")
    }
}
like image 947
richc Avatar asked Sep 03 '25 07:09

richc


1 Answers

If you want to get all connected peripherals, my suggestion is: add string 180A as a parameter to retrieveConnectedPeripherals. All Bluetooth Smart devices implement the DEVICE INFORMATION (180A) service (at least this one).

like image 105
Marcel Mendes Filho Avatar answered Sep 04 '25 20:09

Marcel Mendes Filho