使用CoreBluetooth检测Apple Watch

问题描述 投票:2回答:2

我正在用iPhone的Core Bluetooth发现蓝牙设备,但它没有接收到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;
}
}
ios bluetooth core-bluetooth apple-watch
2个回答
0
投票

当我运行以下代码时,我的Apple Watch出现了。

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

180A 是设备信息服务

不知道你可以发现和订阅哪些特征,如果有的话,但你肯定可以检测到手表的存在。


-1
投票
© www.soinside.com 2019 - 2024. All rights reserved.