2014-03-03 66 views
0

我有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

回答

0

如果從不調用centralManager:didDiscoverPeripheral:advertisementData:RSSI:,這可能意味着沒有提供CBUUID的外設。您可以嘗試提供nil而不是服務陣列,並檢查是否有可用的外設(不要在生產模式下執行此操作)。

+0

試圖讓這些[centralManager scanForPeripheralsWithServices:無選項:無];但仍未在didDiscoverPeripheral委託中獲得通知。 – Abo3atef

+0

但是,我昨天連接到設備的問題,我在centralManager中收到通知:didDiscoverPeripheral:advertisementData:RSSI 我可以記錄設備的名稱,這表示設備是低能耗設備! 但現在我無法連接到它! 即使我試圖把代碼放在項目上的不同位置,它沒有給出任何迴應! – Abo3atef

0

好吧,我想我發送郵件給TaiDoc公司後發現問題,他們告訴我這些設備不支持i​​Phone藍牙整合。

我試圖連接Tom-Tom GPS watch,它已成功連接:) 所以我認爲問題的問題是硬件問題。