我有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)無法發現外圍設備,這是我的葡萄糖設備。
當我從設置 - >藍牙搜索時找不到設備。
嘗試:'[centralManager scanForPeripheralsWithServices:nil options:nil];',那麼我們會看到。我沒有看到你的設備是否真的是BLE或不是你的鏈接,並且'centralManagerDidUpdateState'什麼時候到'CBCentralManagerStatePoweredOn',然後你做了掃描? – Larme
試圖使這些[centralManager scanForPeripheralsWithServices:無選項:無]; 但仍未在didDiscoverPeripheral委託中獲得通知。 – Abo3atef