[英]Couldn't Discover Peripheral in Core Bluetooth
I've iPhone app and I want to connect with bluetooth device to get Glucose Measurements. 我有iPhone应用程序,我想与蓝牙设备连接以获得葡萄糖测量值。 You can find the device from here . 您可以从这里找到设备。
After reading Apple documentation about Core Bluetooth I started reading these tutorial . 在阅读了有关Core Bluetooth的Apple文档之后,我开始阅读这些教程 。 Also I get the services ID's for bluetooth devices from these link here 此外,我得到了服务ID的蓝牙设备从这些链接在这里
So I started to code like in the tutorial after understanding the basics. 因此,在了解了基础知识之后,我便开始像本教程中那样编写代码。
And these my Code: 这些是我的代码:
#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;
And I've implemented the delegates for CBCentralManagerDelegate and CBPeripheralDelegate 我已经实现了CBCentralManagerDelegate和CBPeripheralDelegate的委托
I receive a notification for centralManagerDidUpdateState
我收到有关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");
}
}
My NSLog logs : CoreBluetooth BLE hardware is powered on and ready.
我的NSLog日志: CoreBluetooth BLE hardware is powered on and ready.
But I did not receive a notification for central didDiscoverPeripheral
. 但是我没有收到有关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];
}
}
These method is not being called. 这些方法没有被调用。
So the central (my iPhone) couldn't discover the Peripheral which is my Glucose device. 因此,中央(我的iPhone)无法找到作为我的葡萄糖设备的外围设备。
I couldn't find the device when I search for it from Setting ->Bluetooth. 从设置->蓝牙搜索设备时找不到设备。
If centralManager:didDiscoverPeripheral:advertisementData:RSSI:
is never called, this likely means that there is no peripheral with one of provided CBUUIDs. 如果从不调用centralManager:didDiscoverPeripheral:advertisementData:RSSI:
则可能意味着没有外围设备具有提供的CBUUID之一。 You could try to provide nil
instead of the services-array and check if there is any peripheral available (don't do this in production mode). 您可以尝试提供nil
而不是services-array,并检查是否有可用的外围设备(不要在生产模式下执行此操作)。
OK, I think I figured out the problem after sending email to TaiDoc company they told me that these device dose not support iPhone bluetooth integration. 好的,我认为在向TaiDoc公司发送电子邮件后发现了问题,他们告诉我这些设备不支持iPhone蓝牙集成。
I tried to connect with Tom-Tom GPS watch and it's connected successfully :) So I think the problem of the issue is a Hardware issue. 我试图与Tom-Tom GPS手表连接,并且连接成功:)因此,我认为这个问题是硬件问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.