I want to get a list of the currently connected Bluetooth/BLE devices to my device.
I tried to lock in Core Bluetooth
documentation, but didn't find something that can help me with the task.
Is it possible to get the list of the currently connected devices, and if so, which direction should I look in?
Asked
Active
Viewed 903 times
1

Keselme
- 3,779
- 7
- 36
- 68
-
Does this answer your question? [How to get list of available Bluetooth devices?](https://stackoverflow.com/questions/10178293/how-to-get-list-of-available-bluetooth-devices) – El Tomato May 09 '21 at 13:05
-
@ElTomato, not exactly, I'm not looking for the available BT devices, I want to get a list of those that I'm already connected to. – Keselme May 09 '21 at 15:22
-
I see at least one topic if I search for BLE connected devices. – El Tomato May 09 '21 at 23:50
-
You can get CBPeripheral objects using the method retrievePeripherals(withIdentifiers:) of the CBCentralManager class. However, this method takes as input the UUID of the peripheral so you can get only peripherals that you have already connected/discovered previously. – Andrea Gorrieri May 13 '21 at 06:57
-
@AndreaGorrieri, do you mean peripherals that I connected through the app or using the general Bluetooth of the iPhone? – Keselme May 13 '21 at 07:27
-
I mean peripherals that you have connected through your app previously, (you need to know the UUID related to the peripheral and this comes as a result of a BLE scan). I think you can't get peripherals that have never been connected by your app. – Andrea Gorrieri May 13 '21 at 08:18
-
@AndreaGorrieri, I tested something - I completely removed my app and Forgot the device I was connected to. Then I used `retrievePeripherals(withIdentifiers:)` method with the identifier of the device - I got a result without even connecting to it in anyway, do you know why is it possible? – Keselme May 13 '21 at 08:46
-
As long as you have the UUID of the peripheral you can try to retrieve it with the retrievePeripherals method... however, take into account that UUID are NOT unique on different phones and they can change if you reinstall the application. – Andrea Gorrieri May 13 '21 at 08:53
1 Answers
1
No such method is provided by Apple yet. But you can use
retrieveConnectedPeripherals(withServices serviceUUIDs: [CBUUID]) -> [CBPeripheral]
method of CBCentralManager class.
You can review this similar question for more details How get the list of paired bluetooth devices in swift?

Milankumar Parmar
- 63
- 7
-
Thanks, I tried to look into this method, but I don't know the service uuids I'm looking for, and if I pass an empty array I get an empty array in return. My end goal is to know that the user is in a car and his phone is connected to the car's bluetooth. – Keselme May 18 '21 at 06:40
-
In order to know about "classic" Bluetooth connections (A2DP or HFP devices NOT BLE) you have to check AVAudioSession rather than CoreBluetooth. See AVAudioSession.routeChangeNotification, and AVAudioSession.Port. – Andrea Gorrieri Jun 10 '21 at 10:07