LightBlue 找到但 iOS CoreBluetooth 找不到的设备

Device found by LightBlue but not iOS CoreBluetooth

我在 Arduino 上使用 BLE Shield - LightBlue 正确检测到 BLE Shield。现在,我正在尝试制作一个应用程序来扫描所有 BLE 设备并连接到正确的设备,这样我就可以从我的应用程序向我的盾牌发送一些信息。

但该应用程序未检测到 BLE Shield(但它检测到另一个 BLE 设备...)。

我的代码如下:

- (void)centralManagerDidUpdateState:(CBCentralManager *)central{

    switch (central.state) {
        case CBCentralManagerStatePoweredOn:
            msg=[NSString stringWithFormat:@"Bluetooth is currently powered on and available to use."];
            [cbcManager scanForPeripheralsWithServices:[NSArray arrayWithObject:[CBUUID UUIDWithString:@"180A"]] options:nil];
            break;
    }
}

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:   (CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
    NSLog(@"%@\n--------------------", advertisementData.description);
}

我与 LightBlue 核对过,180A 是我的防护罩的正确服务 UUID。我也尝试通过传递 nil 值而不是服务 UUID 来进行扫描,但仍然无法检测到它。

代码似乎可以正常工作,因为找到了我的一个 BLE 设备...知道为什么我的防护罩可以被 LightBlue 而不是这段代码检测到吗?

您可以尝试在扫描时传递允许重复选项,因为如果它认为它是重复的,它的发现可能会被抑制。

NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];    

[cbcManager scanForPeripheralsWithServices:nil options:options];