Implement your own GameController through Bluetooth

Hello there,


This might be unusual or unexpected : I want to use my iOS device as a GameController for an OSX or even tvOS (or even iOS) app.

I have started to create a "receiver" (CBCentralManager) and the "sender" (the controller, CBPeripheralManager).

Goal is to simulate a gamepad and also send motions.

So far it's easy, GCGamepad has some handy functions like GCGamepadSnapshot to/from NSData so it's very convenient to send over bluetooth.

..and you achieve a sender (iOS) that can sends these snapshot and also CMDeviceMotion to a receiver that creates a GCController. Since OSX /tvOS don't have CoreMotion.framework but have GCMotion instead, you just make your own way to pass the data through.


It becomes an issue when creating the GCController. This class is not intended to be mutable. To be able to move forward I created my own mutable subclasses of GCController, GCControllerButtonInput, GCMotion, GCGamepad, etc. (which is really not convenient, but does the job!)


But here comes real questions : how does constructor get there devices directly interpreted as GCControllers over Bluetooth?

The way I do it is just a software trick with the intention of using the GameController api where I would not obviously need it (unless I want to harmonize this to work along with real controllers). I am using strict CBUUID decided/generated on my own but I believe there must be some official specs that would make it work directly without the need of creating my own mutable GCController. Any suggestions?


Thank you in advance community,

- Quentin

Replies

I looked for ways to do what you are describing, but I gave up. There's what seems to be an answer to your question in this thread - I've not tried that approach: https://forums.developer.apple.com/message/18071#18071


Instead of that approach, and instead of trying to descend from GCController, I created a wrapper around GCController, that uses NSNetservice for network communication between the game and software controllers. https://github.com/robreuss/VirtualGameController