2015-12-29 94 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。 –

相关问题