diff options
| author | Teddy Wing | 2019-03-24 12:45:52 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2019-03-24 12:50:05 +0100 | 
| commit | c484af9d5844fa29be77d098542a74e313dad4c6 (patch) | |
| tree | 35208ff1acad0c5df50a5471fe3d677994e5324a | |
| parent | 519038bde17082020265d5ae5bda80f493f91b20 (diff) | |
| download | DomeKey-c484af9d5844fa29be77d098542a74e313dad4c6.tar.bz2 | |
HeadphoneKeyEventBluetooth: Listen for Bluetooth device pairing
Register a delegate that gets called when Bluetooth devices are paired
with the Mac.
We now need to determine if the paired device is a pair of headphones
(ideally if we can figure out media remote control capability that would
be helpful), and then connect to them over L2CAP to get AVRCP messages.
The `devicePairingFinished:error:` delegate method was a test. Leaving
it in as a reminder that we also need to implement functionality that
looks for already-connected Bluetooth headphones when DomeKey launches.
| -rw-r--r-- | DomeKey/HeadphoneKeyEventBluetooth.h | 3 | ||||
| -rw-r--r-- | DomeKey/HeadphoneKeyEventBluetooth.m | 27 | 
2 files changed, 19 insertions, 11 deletions
| diff --git a/DomeKey/HeadphoneKeyEventBluetooth.h b/DomeKey/HeadphoneKeyEventBluetooth.h index 86e0ce7..a55a539 100644 --- a/DomeKey/HeadphoneKeyEventBluetooth.h +++ b/DomeKey/HeadphoneKeyEventBluetooth.h @@ -7,11 +7,12 @@  //  #import <Foundation/Foundation.h> +#import <IOBluetooth/IOBluetooth.h>  #import "HeadphoneKeyEventDelegate.h"  #import "dome_key_map.h" -@interface HeadphoneKeyEventBluetooth : NSObject { +@interface HeadphoneKeyEventBluetooth : NSObject <IOBluetoothDevicePairDelegate> {      id <HeadphoneKeyEventDelegate> _delegate;  } diff --git a/DomeKey/HeadphoneKeyEventBluetooth.m b/DomeKey/HeadphoneKeyEventBluetooth.m index 52e22db..839a4ba 100644 --- a/DomeKey/HeadphoneKeyEventBluetooth.m +++ b/DomeKey/HeadphoneKeyEventBluetooth.m @@ -16,20 +16,27 @@      if (self) {          _delegate = delegate; -        MPRemoteCommandCenter *cc = [MPRemoteCommandCenter sharedCommandCenter]; -        [cc playCommand]; -        [cc pauseCommand]; -        [cc stopCommand]; -        [cc togglePlayPauseCommand]; -        // [cc nextTrackCommand]; -        // [cc seekForwardCommand]; -        // [cc previousTrackCommand]; -        // [cc seekBackwardCommand]; +        IOBluetoothUserNotification *notification = [IOBluetoothDevice +            registerForConnectNotifications:self +            selector:@selector(connectNotification:forDevice:)]; +        if (!notification) { +            // TODO: error +            NSLog(@"Connection notification error"); +        }      }      return self;  } -MPRemoteCommandHandler key_pressed(HeadphoneButton button) { +- (void)devicePairingFinished:(id)sender +    error:(IOReturn)error +{ +    NSLog(@"Paired: %@", sender); +} + +- (void)connectNotification:(IOBluetoothUserNotification *)notification +    forDevice:(IOBluetoothDevice *)device +{ +    NSLog(@"Paired notification: %@ ; Device: %@", notification, device);  }  @end | 
