From 28a6eafbf3ba46abe4560cecd4696457f5615137 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 24 Mar 2019 19:10:40 +0100 Subject: 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. --- DomeKey/HeadphoneKeyEventBluetooth.m | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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 -- cgit v1.2.3