2015-12-29 45 views
2

我發現使用我的iPhone上的Core Bluetooth的藍牙設備,但它沒有拿起Apple Watch。有什麼我失蹤?下面是我使用下面的代碼:使用CoreBluetooth檢測Apple Watch

#pragma mark - CBCentralManagerDelegate 

// method called whenever you have successfully connected to the BLE peripheral 
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral 
{ 
} 

// CBCentralManagerDelegate - This is called with the CBPeripheral class as its main input parameter. This contains most of the information there is to know about a BLE peripheral. 
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI 
{  NSLog(@"%@", [peripheral name]); 
} 


// method called whenever the device state changes. 
- (void)centralManagerDidUpdateState:(CBCentralManager *)central 
{ 
switch ([central state]) 
{ 
    case CBCentralManagerStatePoweredOff: 
     NSLog(@"CoreBluetooth BLE hardware is powered off"); 
     break; 
    case CBCentralManagerStatePoweredOn: 
     NSLog(@"CoreBluetooth BLE hardware is powered on and ready"); 
     [[self bluetoothManager] scanForPeripheralsWithServices:nil options:nil]; 
     break; 
    case CBCentralManagerStateResetting: 
     NSLog(@"CoreBluetooth BLE hardware is resetting"); 
     break; 
    case CBCentralManagerStateUnauthorized: 
     NSLog(@"CoreBluetooth BLE state is unauthorized"); 
     break; 
    case CBCentralManagerStateUnknown: 
     NSLog(@"CoreBluetooth BLE state is unknown"); 
     break; 
    case CBCentralManagerStateUnsupported: 
     NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform"); 
     break; 
    default: 
     break; 
} 
} 
+0

如果Core Blietooh能夠發現Apple Watch,我會感到驚訝。 – Paulw11

+0

1)您是否在中央狀態爲PoweredOn時檢查外圍設備,以及2)您確定手錶上的藍牙是否已打開? – 7thFox

+0

@ josh951623是的,我是。手機的藍牙是PoweredOn,手錶上的藍牙已打開。 –

回答

0

我的Apple關注表明,當我運行下面的代碼:

[self.centralManager retrieveConnectedPeripheralsWithServices:@[[CBUUID UUIDWithString:@"180A"]]]; 

180A是設備信息服務。

不確定您可以發現和訂閱哪些特徵(如果有),但您絕對可以檢測手錶的存在。

+0

今天我要測試一下。謝謝! –

+0

這是可以從應用程序委託嗎?即使在確認CBCentralManagerStatePoweredOn後,我仍然看不到任何內容。 –

+0

這很奇怪,我在'CBCentralManagerStatePoweredOn'上看到'centralManagerDidUpdateState'上面的代碼。如果我關掉手錶,它就會消失。也許這是一個錯誤,我的手錶處於滑稽狀態 - 我無法將它更新到2.1。 –