1

我们如何BLE GATTConnect在不扫描的情况下在 iOS 中执行外围设备(已经知道外围设备的硬件地址)?

我更熟悉Android,知道Android中的解决方案,我正在寻找如何在iOS中完成上述操作。上面可以使用BluetoothDevice object可以使用hardware address. Hardware address可以通过应用程序以任何方式获取,而不仅仅是扫描。

在 iOSconnectPeripheral方法中,CBCentralManager需要CBPeripheral object一个连接到GATT server. CBPeripheral为中央设备看到的每个广告返​​回 的实例。

在我们的 iOS 应用程序中,我们知道hardware address外围设备的(广告中的 6 字节地址),并且还知道设备何时广告准备连接。

问题:

在 iOS 中,我们如何在不知道外围设备的硬件地址的情况下与外围设备连接?

4

1 回答 1

2

我认为您必须进行扫描,但在didDiscoverPeripheralCBCentralManager 代表中,您可以检查advertisementData您的“地址”的制造商数据字段

//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.
 }
于 2015-02-03T17:03:30.770 回答