diff options
| author | Teddy Wing | 2019-03-24 19:10:40 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2019-03-24 19:10:40 +0100 | 
| commit | 28a6eafbf3ba46abe4560cecd4696457f5615137 (patch) | |
| tree | 48b208557601179b52d16f2a3c75e5c0755428e3 | |
| parent | c484af9d5844fa29be77d098542a74e313dad4c6 (diff) | |
| download | DomeKey-28a6eafbf3ba46abe4560cecd4696457f5615137.tar.bz2 | |
HeadphoneKeyEventBluetooth: Determine Bluetooth device class
Learn how to find out if a device is a pair of headphones with remote
control capabilities.
This produces the following output:
    2019-03-24 19:07:46.265 DomeKey[59146:1474861] Device class major: 4
    2019-03-24 19:07:46.266 DomeKey[59146:1474861] Device class minor: 6
    2019-03-24 19:07:46.266 DomeKey[59146:1474861] Class of device: 2360344
    2019-03-24 19:07:46.266 DomeKey[59146:1474861] Service class major: 288
    2019-03-24 19:07:46.266 DomeKey[59146:1474861] Major audio
    2019-03-24 19:07:46.266 DomeKey[59146:1474861] Minor audio
    2019-03-24 19:07:46.266 DomeKey[59146:1474861] Is remote controller
Other potentially useful but unused constants are:
    kBluetoothSDPUUID16ServiceClassAVRemoteControlTarget
    kBluetoothSDPUUID16ServiceClassAVRemoteControl
    kBluetoothSDPUUID16ServiceClassAVRemoteControlController
in IOBluetooth's `BluetoothAssignedNumbers.h`.
From this, we should be able to figure out if a device is a remote
control-capable pair of headphones.
| -rw-r--r-- | DomeKey/HeadphoneKeyEventBluetooth.m | 31 | 
1 files changed, 31 insertions, 0 deletions
diff --git a/DomeKey/HeadphoneKeyEventBluetooth.m b/DomeKey/HeadphoneKeyEventBluetooth.m index 839a4ba..74ae8b9 100644 --- a/DomeKey/HeadphoneKeyEventBluetooth.m +++ b/DomeKey/HeadphoneKeyEventBluetooth.m @@ -37,6 +37,37 @@      forDevice:(IOBluetoothDevice *)device  {      NSLog(@"Paired notification: %@ ; Device: %@", notification, device); +// 200418 +    NSLog(@"Device class major: %u", [device deviceClassMajor]); +    NSLog(@"Device class minor: %u", [device deviceClassMinor]); +    NSLog(@"Class of device: %u", [device classOfDevice]); +    NSLog(@"Service class major: %u", [device serviceClassMajor]); + +    // for (int i = 0; i < [[device services] count]; i++) { +    //     NSLog(@"Service: %@", [[device services] objectAtIndex:i]); +    // } + +    if ([device deviceClassMajor] == kBluetoothDeviceClassMajorAudio) { +        NSLog(@"Major audio"); +    } +    if ([device deviceClassMinor] == kBluetoothDeviceClassMinorAudioHeadphones) { +        NSLog(@"Minor audio"); +    } +    if ([device serviceClassMajor] == kBluetoothServiceClassMajorAudio) { +        NSLog(@"Service major audio"); +    } +    if ([device deviceClassMajor] == kBluetoothDeviceClassMajorAudio +            && [device deviceClassMinor] == kBluetoothDeviceClassMinorAudioHeadphones +            && [device serviceClassMajor] == kBluetoothServiceClassMajorAudio) { +        NSLog(@"Is audio device"); +    } + +    IOBluetoothSDPServiceRecord *service_record = [device +        getServiceRecordForUUID:[[IOBluetoothSDPUUID alloc] +            initWithUUID16:kBluetoothSDPUUID16ServiceClassAVRemoteControlController]]; +    if (service_record) { +        NSLog(@"Is remote controller"); +    }  }  @end  | 
