Can I create a list of connected Bluetooth devices for iOS?

I am trying to determine which devices are connected via bluetooth in iOS, but it seems I cannot figure it out. Ideally, I would like to create a list of connected Bluetooth devices.

I tried using "retrieveConnectedPeripheralsWithServices", but this requires a specific service to search. I would like to create a list of all connected bluetooth devices, not just bluetooth enabled devices. Is there a way to just search for all services without getting stuck in all possible services?

Any ideas?

+7
ios swift bluetooth
source share
1 answer

Here is the solution for iOS (thanks to Larme):

NSArray *connectedAccessories = [[EAAccessoryManager sharedAccessoryManager] connectedAccessories]; 

:

https://developer.apple.com/library/prerelease/ios/documentation/ExternalAccessory/Reference/EAAccessoryManager_class/index.html#//apple_ref/occ/instp/EAAccessoryManager/connectedAccessories

Also, if anyone needs this, this is the documentation for Mac:

https://developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/Bluetooth/BT_Intro/BT_Intro.html

and code snippet for Mac

 NSArray *devices = [IOBluetoothDevice pairedDevices]; 

For the question alan478 BLE:

The basic Bluetooth infrastructure provides the classes required for iOS and Mac applications to communicate with devices equipped with Bluetooth wireless technology. You can watch this lesson:

http://www.raywenderlich.com/52080/introduction-core-bluetooth-building-heart-rate-monitor

and the BLE code snippet:

 // In this case you need to tell UUID for serching specific device CBUUID *hrate = [CBUUID UUIDWithString:@"1800"]; // 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:hrate] options:scanOptions] 

Please read this document at developer.apple.com:

https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/BestPracticesForInteractingWithARemotePeripheralDevice/BestPracticesForInteractingWithARemotePeripheralDevice.html

Here is an interesting paragraph for you:

Explore peripheral device data wisely A peripheral device may have many more services and features than you might be interested in when you design an application to fulfill a specific use case. Detecting all peripheral services and related features can adversely affect battery life and the performance of your applications. Therefore, you should search and discover only those services and related characteristics that you need.

For example, imagine that you are connected to a peripheral device with many services available, but your application only needs access to two of them. You can search and discover only these two services by passing the DiscoverServices method: CBPeripheral class to the array of your service UUIDs (represented by CBUUID objects), for example:

 [peripheral discoverServices:@[firstServiceUUID, secondServiceUUID]]; 

After you find two services that interest you, you can also search and find only those characteristics of these services that are of interest to you. Again just pass an array of UUIDs that identifies the characteristics you want to discover (for each service) the DiscoverCharacteristics: forService: property of the CBPeripheral class method.

There is also this comment:

"I think that Apple forbids this thing. We can get a list of devices with a specific CBUUID, so if you want to list all devices (the same as the Bluetooth settings, initially), then this is not possible. I'm wrong. - Mrug Mar 11 at 13 : 24 "

about this question:

How to get a list of available bluetooth devices?

+3
source share

All Articles