SC-SL
SC-SL

Reputation: 377

In iOS how to connect to Peripheral without scanning using the harware address

How can we perform a BLE GATTConnect to a peripheral device in iOS without scanning (already knowing the hardware address of the peripheral device)?

I am more familiar with Android, knowing the solution in Android, I am looking for how above can be done in iOS. The above can be performed using the BluetoothDevice object which can be created using a hardware address. Hardware address can be obtained in any way by the application, not just be scanning.

In iOS connectPeripheral method of CBCentralManager requires a CBPeripheral object to make a connection to the GATT server. Instance of the CBPeripheral is returned for each advertisement seen by the central device.

In our iOS application,We know the hardware address (6 byte address in the advertisement) of peripheral and also know when the device is advertising ready to be connected.

Question:

In iOS how do we connect with the peripheral without performing a scan knowing the hardware address of the peripheral?

Upvotes: 1

Views: 1230

Answers (1)

Jeffrey Stewart
Jeffrey Stewart

Reputation: 567

I think that you will have to do a scan, but in the didDiscoverPeripheral CBCentralManager Delegate, you can check the Manufacturer Data field of the advertisementData for your 'address'

//CBCentralManager Delegate
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
    //Pull the localName and manufacturing Data out of the advertising data
    NSString *localName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
    NSData   *mfgData   = [advertisementData objectForKey:CBAdvertisementDataManufacturerDataKey];

    //Now check for your 'address' in mfgData and connect if it matches.
 }

Upvotes: 2

Related Questions