繁体   English   中英

在核心蓝牙中无法发现外围设备

[英]Couldn't Discover Peripheral in Core Bluetooth

我有iPhone应用程序,我想与蓝牙设备连接以获得葡萄糖测量值。 您可以从这里找到设备。

在阅读了有关Core Bluetooth的Apple文档之后,我开始阅读这些教程 此外,我得到了服务ID的蓝牙设备从这些链接在这里

因此,在了解了基础知识之后,我便开始像本教程中那样编写代码。

这些是我的代码:

#define POLARH7_HRM_DEVICE_INFO_SERVICE_UUID @"180A" // for Device Information service.
#define POLARH7_HRM_HEART_RATE_SERVICE_UUID @"1808" // For Glucose service.

NSArray *services = @[[CBUUID UUIDWithString:POLARH7_HRM_HEART_RATE_SERVICE_UUID], [CBUUID UUIDWithString:POLARH7_HRM_DEVICE_INFO_SERVICE_UUID]];
CBCentralManager *centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[centralManager scanForPeripheralsWithServices:services options:nil];
self.centralManager = centralManager;

我已经实现了CBCentralManagerDelegate和CBPeripheralDelegate的委托

我收到有关centralManagerDidUpdateState的通知

- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
    // Determine the state of the peripheral
    if ([central state] == CBCentralManagerStatePoweredOff) {
        NSLog(@"CoreBluetooth BLE hardware is powered off");
    }
    else if ([central state] == CBCentralManagerStatePoweredOn) {
        NSLog(@"CoreBluetooth BLE hardware is powered on and ready");
    }
    else if ([central state] == CBCentralManagerStateUnauthorized) {
        NSLog(@"CoreBluetooth BLE state is unauthorized");
    }
    else if ([central state] == CBCentralManagerStateUnknown) {
        NSLog(@"CoreBluetooth BLE state is unknown");
    }
    else if ([central state] == CBCentralManagerStateUnsupported) {
        NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform");
    }
}

我的NSLog日志: CoreBluetooth BLE hardware is powered on and ready.

但是我没有收到有关central didDiscoverPeripheral的通知。

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
    NSString *localName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
    if ([localName length] > 0) {
        NSLog(@"Found the heart rate monitor: %@", localName);
        [self.centralManager stopScan];
        self.polarH7HRMPeripheral = peripheral;
        peripheral.delegate = self;
        [self.centralManager connectPeripheral:peripheral options:nil];
    }
}

这些方法没有被调用。

因此,中央(我的iPhone)无法找到作为我的葡萄糖设备的外围设备。

从设置->蓝牙搜索设备时找不到设备。

如果从不调用centralManager:didDiscoverPeripheral:advertisementData:RSSI:则可能意味着没有外围设备具有提供的CBUUID之一。 您可以尝试提供nil而不是services-array,并检查是否有可用的外围设备(不要在生产模式下执行此操作)。

好的,我认为在向TaiDoc公司发送电子邮件后发现了问题,他们告诉我这些设备不支持i​​Phone蓝牙集成。

我试图与Tom-Tom GPS手表连接,并且连接成功:)因此,我认为这个问题是硬件问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM