在iOS中,如何在不使用骚扰软件地址扫描的情况下连接到外围设备



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

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

在iOS中connectPeripheral CBCentralManager方法需要CBPeripheral object才能连接到GATT server。为中央设备看到的每个播发返回CBPeripheral实例。

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

问题:

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

我认为您必须进行扫描,但是在didDiscoverPeripheral CBCentralManager代表中,您可以检查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.
 }

最新更新