19

I need to get the list of paired bluetooth devices(iOS Devices) as same as the list in 'Bluetooth' section in iOS settings as shown in below picture.

enter image description here

Is it possible?
Have you seen any apps doing this type of functionality?

I have tried the following: link1, link2, link3, link4, link5, link6

But nothing helped me clearly to get the exact list. I hope there should be a way to achieve this. Please help me by sharing your experience. Thank you.

Community
  • 1
  • 1
Ashok
  • 5,585
  • 5
  • 52
  • 80
  • 1
    You can retrieve the details of BLE devices that are paired/connected but not legacy devices such as headsets/hands free etc – Paulw11 Jan 04 '16 at 21:55
  • Okay, Thanks. Can you provide me the guidelines towards working solution to make the list of BLE devices that are paired/connected ? – Ashok Jan 05 '16 at 06:03
  • @Paulw11 I'd be interested too as I don't know about an API that lists disconnected devices. For connected devices there is the [- retrieveConnectedPeripheralsWithServices:](https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/CBCentralManager_Class/index.html#//apple_ref/occ/instm/CBCentralManager/retrieveConnectedPeripheralsWithServices:) API. – allprog Jan 05 '16 at 06:43
  • @allprog. Any idea about paired(But not connected currently) devices? – Ashok Jan 05 '16 at 07:05
  • @Paulw11. I see the line "However, there is no API to list the paired devices" in your answer at http://stackoverflow.com/a/28342831/1996294 . Are you sure about this? – Ashok Jan 05 '16 at 07:21
  • I'm facing a different scenario in iOS devices regarding bluetooth, posted at http://apple.stackexchange.com/q/222238/61860. Any idea? – Ashok Jan 05 '16 at 08:07
  • I want to detect bluetooth headsets/car deck, but its not showing up. How should I get that name? Its showing under Settings>Bluetooth screen. – MilanPanchal Mar 02 '16 at 12:17
  • @milanpanchal, Refer the links mentioned in above Question and see if you can solve the problem. – Ashok Mar 02 '16 at 13:07
  • No, Actually I didn't get much time to do R&D on this. Refer the links provided in the question, look at any other resources that will be useful to dig this. If you find anything, please post it here, that will be helpful. Thanks. – Ashok Apr 27 '16 at 14:20
  • So I think the answer to this is easy, if you read the docs: ` CBCentralManager objects are used to manage discovered or connected remote peripheral devices (represented by CBPeripheral objects), including scanning for, discovering, and connecting to advertising peripherals.` The device is paired with your phone, it is not ADVERTISING anything outside of that paired encrypted channel. –  Apr 28 '16 at 08:04
  • Hello! just wanted to know any update on this question? are we still unable to show paired devices in iOS? if there isn't any way to show pair devices then how come some smart watch and headsets apps are showing their paired devices in their app?. Thanks – Anas Iqbal Jan 19 '22 at 00:07

3 Answers3

20

It's not possible to retrieve list of paired peripherals from iOS. Neither it's possible to check if specific peripheral is paired.

Retrieving peripheral which is paired

There are two cases which you need to consider:

  1. Peripheral may be already connected in the system (iOS connects automatically with some peripherals in order to for example display battery level). In this case peripheral won't be broadcasting and detection using scanForPeripherals won't work.

  2. Peripheral is paired, but disconnected. In this case retrieveConnectedPeripherals(withServices:) won't work.

Therefore to retrieve your peripheral you need to combine both things. First you need to check if it's in peripherals returned from retrieveConnectedPeripherals(withServices:). If not you should scanForPeripherals.

If you want to retrieve peripheral which is out of range, you can try to use retrievePeripherals(withIdentifiers:), however it may return also not paired devices and it relies on peripheral's UUID which you have to save after pairing.

Detecting if peripheral is paired

There is one way to detect if the specific peripheral is paired. You need to try to read from protected characteristic (which requires encryption - bonding). If you receive expected data, it means that user accepted pairing request. Otherwise you will receive empty response or none.

References

You can read more about Bluetooth in my articles:

Wojciech Kulik
  • 7,823
  • 6
  • 41
  • 67
1

You can use ShowBluetoothAccessoryPicker if you are using the Classic Bluetooh into an MFi device.

https://developer.apple.com/documentation/externalaccessory/eaaccessorymanager/1613913-showbluetoothaccessorypicker

The code below is a C# but you can easily convert it into the IOS (object c your swift)

EAAccessoryManager.SharedAccessoryManager.ShowBluetoothAccessoryPicker(null, completion: ((Foundation.NSError error) => {
                Console.WriteLine("My callback");
                if (error != null && (uint)error.Code != (uint)EABluetoothAccessoryPickerError.AlreadyConnected)
                {
                    Console.WriteLine(String.Format("Error code: {0} Desc: {1}", error.Code, error.DebugDescription));
                    Console.WriteLine("Failed? " + EABluetoothAccessoryPickerError.Failed.ToString());
                    Console.WriteLine("Failed? " + Convert.ToInt64(EABluetoothAccessoryPickerError.Failed));
                }
            }));
Romer
  • 21
  • 3
-1

You need to find the service UUID in which you are interested, in my case it works perfectly,

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[self.centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:SERVICE_UUID]]
                                            options:options];

and when it will find any device which advertise same service UUID, then it will appear in the screen which you have pointed above.

handle didDiscoverperipherel in this way:

-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{

    _discoveredPeripheral = peripheral;

    if(![self.mRemoteDevices containsObject:_discoveredPeripheral])
    {
         NSArray *peripherels = [self.centralManager retrievePeripheralsWithIdentifiers:@[_discoveredPeripheral.identifier]];
        [self.mRemoteDevices addObject:[peripherels objectAtIndex:0]];
    }
}
itsji10dra
  • 4,603
  • 3
  • 39
  • 59
manish
  • 109
  • 1
  • 11