I came across this new API from iOS 7.
- (NSArray *)retrieveConnectedPeripheralsWithServices:(NSArray *)serviceUUIDs NS_AVAILABLE(NA, 7_0);
So its pretty clear that if the return array count is greater than 0 than its connected to atleast one device.
But before using this API I am not able to figure it out the argument (serviceUUIDs) that I have to passed here.
Can someone explain here with an example?
You can't use this method unless you know at least one service exposed by the device. You could try using a common service, such as Device Information - 0x180A - as most BLE devices will advertise this service but it is not guaranteed.
CBUUID *deviceInfoUUID = [CBUUID UUIDWithString: @"180A"];
[cbCentral retrieveConnectedPeripheralsWithServices:@[deviceInfoUUID]];
Legacy audio devices (headsets, A2DP devices etc) are visible as audio devices through the audio session classes -
Detect attached audio devices iOS
The services and characteristics of a peripheral are identified by 128-bit Bluetooth-specific UUIDs, which are represented in the Core Bluetooth framework by CBUUID objects. Though not all UUIDs that identify a service or characteristic are predefined by the Bluetooth Special Interest Group (SIG), Bluetooth SIG has defined and published a number of commonly used UUIDs that have been shortened to 16-bits for convenience. For example, Bluetooth SIG has predefined the 16-bit UUID that identifies a heart rate service as 180D. This UUID is shortened from its equivalent 128-bit UUID, 0000180D-0000-1000-8000-00805F9B34FB, which is based on the Bluetooth base UUID that is defined in the Bluetooth 4.0 specification, Volume 3, Part F, Section 3.2.1.
The CBUUID class provides factory methods that make it much easier to deal with long UUIDs when developing your app. For example, instead of passing around the string representation of the heart rate service’s 128-bit UUID in your code, you can simply use the UUIDWithString method to create a CBUUID object from the service’s predefined 16-bit UUID, like this:
CBUUID *heartRateServiceUUID = [CBUUID UUIDWithString: @"180D"];
When you create a CBUUID object from a predefined 16-bit UUID, Core Bluetooth prefills the rest of 128-bit UUID with the Bluetooth base UUID.
For more, please read documentation
Different Bluetooth device offer different services associated with it, and these services offered by a particular device can be identified through a specific UUID associated with it.
For more details on bluetooth services and their respective UUID, please refer following link :
https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx
So when you perform a search you can specify a criteria which suggest the preference of your bluetooth devices to search.
so if you want the bluetooth devices offering the blood pressure and heart rate in your search preference you should them as following :
[bluetoothmanager scanForPeripheralsWithServices:[NSArray arrayWithObjects:[CBUUID UUIDWithString:@"1810"], [CBUUID UUIDWithString:@"180D"], nil] options:nil];
UPDATE :
Refer following heading on the below link:
Discovering Peripheral Devices That Are Advertising
https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/PerformingCommonCentralRoleTasks/PerformingCommonCentralRoleTasks.html#//apple_ref/doc/uid/TP40013257-CH3-SW1
it is mentioned in NOTE that if you pass nil it will return all devices:
Note: If you specify nil for the first parameter, the central manager returns all discovered peripherals, regardless of their supported services. In a real app, you will likely specify an array of CBUUID objects, each of which represents the universally unique identifier (UUID) of a service that a peripheral is advertising. When you specify an array of service UUIDs, the central manager returns only peripherals that advertise those services, allowing you to scan only for devices that you may be interested in.
UUIDs, and the CBUUID objects that represent them, are discussed in more detail in “Services and Characteristics Are Identified by UUIDs.”
So you can use it as following :
[bluetoothmanager scanForPeripheralsWithServices:nil options:nil];
And it will serve your purpose :)