Skip to content

Implementing in Objective C

Rob Reuss edited this page Nov 18, 2015 · 1 revision

Status

I've tested most of the functionality of the framework, but if I missed anything please let me know at virtualgamecontroller@gmail.com.

Objective C Sample Project

A very basic Objective C sample project is included that demonstrates the setup and key method calls for both Peripheral and Central modes.

Project Setup

In Build Settings, the Embedded Content Contains Swift Code setting must be set to YES.

Implementing a Peripheral

  • Notifications must be implemented using the string version of the notification name, rather than the global constants that are offered when using Swift, for example:

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(foundService:) name:@"VgcPeripheralDidConnectNotification" object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(foundService:) name:@"VgcPeripheralDidDisconnectNotification" object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(foundService:) name:@"VgcPeripheralFoundService" object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(foundService:) name:@"VgcPeripheralLostService" object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(foundService:) name:@"VgcPeripheralFoundService" object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(foundService:) name:@"VgcPeripheralDidResetBrowser" object:nil];
  • Setting up a Peripheral device is done as follows (appIdentifier should be changed to something appropriate to your project name):

    [VgcManager startAs:AppRolePeripheral appIdentifier:@"vgc"];
    DeviceInfo * deviceInfo = [[DeviceInfo alloc] initWithDeviceUID:@"" vendorName:@"" attachedToDevice:NO profileType:ProfileTypeExtendedGamepad controllerType:ControllerTypeSoftware supportsMotion:YES];
    [[VgcManager peripheral] setDeviceInfo:deviceInfo];
  • Search for available Centrals and Bridges as follows:

    [[VgcManager peripheral] browseForServices];
  • Send a element value to a Central or Bridge:

    Element * rightTrigger = [[VgcManager elements] rightTrigger];
    rightTrigger.value = @1.0;
    [[VgcManager peripheral] sendElementState:rightTrigger];

Implementing a Central or Bridge

Setting up as a Central is done as follows (appIdentifier should be changed to something appropriate to your project name):

[VgcManager startAs:AppRoleCentral appIdentifier:@"vgc"];

Setting up as a Bridge is done as follows:

[VgcManager startAs:AppRoleBridge appIdentifier:@"vgc"];