简体   繁体   中英

Detecting Apple Watch Using CoreBluetooth

I am discovering bluetooth devices using Core Bluetooth from my iPhone, but it does not pick up the Apple Watch. Is there something I'm missing? Here is the code I'm using below:

#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;
}
}

My Apple Watch shows up when I run the following code:

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

180A is the Device Information service.

Not sure which characteristics you can discover and subscribe to, if any, but you can definitely detect the watch's presence.

U do not use Core Bluetooth to connect to Apple Watch you use another framework called connectivity

https://developer.apple.com/documentation/watchconnectivity/using_watch_connectivity_to_communicate_between_your_apple_watch_app_and_iphone_app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM