How Get the List of Paired Bluetooth Devices in Swift

How to List discoverable Bluetooth devices and already paired devices in iOS, which method to use in swift?

CoreBluetooth only allows you to access Bluetooth Low Energy devices. You can pair these devices if you need encryption but typically you don't.

However, there is no API to list the paired devices - you need to discover the device(s) that are offering the service you are interested in and present a list, if necessary using your own UI in your app. Once you have identified the target device you can initiate a connection.

How to get list of available Bluetooth devices?

This guide looks promising for Bluetooth 3.0. Remember that the CoreBluetooth framework is ONLY for Bluetooth Low Energy (4.0). At bluetooth.com's dev-pages you can see some examples of globally defined services, and as Guan Yang mentionen, you can see that the heart rate service is 0x180D. UUID`s of the unit is defined by the manufacturer.

Here's a code snippet to maybe help you along the way.

// Initialize a private variable with the heart rate service UUID    
CBUUID *heartRate = [CBUUID UUIDWithString:@"180D"];

// Create a dictionary for passing down to the scan with service method
NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];

// Tell the central manager (cm) to scan for the heart rate service
[cm scanForPeripheralsWithServices:[NSArray arrayWithObject:heartRate] options:scanOptions]


Related Topics



Leave a reply



Submit