无法发现核心蓝牙外设

问题描述:

我有iPhone应用程序,我想连接蓝牙设备以获取葡萄糖测量。您可以从here找到该设备。无法发现核心蓝牙外设

阅读关于Core蓝牙的Apple文档后,我开始阅读这些tutorial。我也从这些链接获得蓝牙设备的服务ID here

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

而且我的这些代码:

#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)无法发现外围设备,这是我的葡萄糖设备。

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

+0

尝试:'[centralManager scanForPeripheralsWithServices:nil options:nil];',那么我们会看到。我没有看到你的设备是否真的是BLE或不是你的链接,并且'centralManagerDidUpdateState'什么时候到'CBCentralManagerStatePoweredOn',然后你做了扫描? – Larme

+0

试图使这些[centralManager scanForPeripheralsWithServices:无选项:无]; 但仍未在didDiscoverPeripheral委托中获得通知。 – Abo3atef

如果从不调用centralManager:didDiscoverPeripheral:advertisementData:RSSI:,这可能意味着没有提供CBUUID的外设。您可以尝试提供nil而不是服务阵列,并检查是否有可用的外设(不要在生产模式下执行此操作)。

+0

试图让这些[centralManager scanForPeripheralsWithServices:无选项:无];但仍未在didDiscoverPeripheral委托中获得通知。 – Abo3atef

+0

但是,我昨天连接到设备的问题,我在centralManager中收到通知:didDiscoverPeripheral:advertisementData:RSSI 我可以记录设备的名称,这表示设备是低能耗设备! 但现在我无法连接到它! 即使我试图把代码放在项目上的不同位置,它没有给出任何回应! – Abo3atef

好吧,我想我发送邮件给TaiDoc公司后发现问题,他们告诉我这些设备不支持i​​Phone蓝牙整合。

我试图连接Tom-Tom GPS watch,它已成功连接:) 所以我认为问题的问题是硬件问题。