Search code examples
objective-cinterface-buildernsnotificationcenternsopenglviewgamecontroller

GCController framework (OSX) not generating notifications


I'm trying to integrate the GCController framework into my project. I'm not so familiar with Objective-C, so please excuse my ignorance around how this is supposed to work.

I have a class that extends NSOpenGLView, which registers observer methods for the various controller notifications, like so:

-(void)awakeFromNib
{
    // Do some stuff

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerStateChanged) name:GCControllerDidConnectNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerStateChanged) name:GCControllerDidDisconnectNotification object:nil];
}

and I've defined a super simple handler as such:

- (void)controllerStateChanged {
   NSLog (@"something happened, let's check it out\n");
}

Problem is, these events/notifications never seem to fire - and when I inspect [GCController controllers], it's entirely empty.

Of course, it stands to reason that if there are no controllers, there will be no events - so maybe I'm doing something wrong?

Or perhaps, for whatever reason - my controller simply fails to generate the required events (I'm using a PS4 controller which is registered with the OS, be it wirelessly or via USB, so I'm not sure what I'm missing here).

Is there some other place I need to enable these notifications? Do I need to somehow initialise the GCController framework?


Solution

  • So it turns out that the GCController framework only supports MFi (Made For iPod, Made For iPhone, Made For iPad) controller products.

    For anyone looking to support non-MFi controllers, you'll need to interface with the HID via IOKit. Or use the rather excellent DDHIDLib instead