我有iPhone应用程序,我想连接蓝牙设备以获得葡萄糖测量。您可以从here找到该设备。
在阅读有关Core Bluetooth的Apple文档后,我开始阅读这些tutorial。此外,我从这些链接here
获取蓝牙设备的服务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)无法发现外设这是我的葡萄糖设备。
当我从设置 - >蓝牙中搜索设备时找不到设备。
答案 0 :(得分:0)
如果永远不会调用centralManager:didDiscoverPeripheral:advertisementData:RSSI:
,这可能意味着没有提供CBUUID之一的外围设备。您可以尝试提供nil
而不是services-array,并检查是否有可用的外围设备(请勿在生产模式下执行此操作)。
答案 1 :(得分:0)
好的,我想在向TaiDoc公司发送电子邮件后我发现了问题,他们告诉我这些设备不支持iPhone蓝牙集成。
我尝试连接Tom-Tom GPS watch并且已成功连接:) 所以我认为问题的问题是硬件问题。