1

I'm trying to read the GCController.controllers() array after my app has launched to know which controllers were already connected to the AppleTV at app launch. But GCController.controllers().count is 0 until some point after viewDidAppear gets called on my initial UIViewController. Does anyone know the definitive point by which you can check GCController.controllers() to know that it has been populated with the currently connected controllers?

I am aware of the need to register for controller connection notifications with;

NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleControllerDidConnectNotification:"   , name: GCControllerDidConnectNotification   , object: nil)

But that is for later after launch. First I need to know which ones are already connected. Anyone know?

Geoff H
  • 3,107
  • 1
  • 28
  • 53
  • Anyone know if & how I could key-value observe GCController.controllers() in swift? Anyone? Bueller? ..Bueller? – Geoff H Nov 09 '15 at 08:53

2 Answers2

1

You can call startWirelessControllerDiscoveryWithCompletionHandler on viewDidLoad and then check GCController.controllers() on viewWillAppear that seem to work for the game app I just finished.

Docs:

After your app has finished launching, the operating system automatically creates a list of connected controllers. Call the controllers class method to retrieve an array of GCController objects for all connected controllers. Next, use these objects to configure the controllers or read the controller’s inputs. If there are no connected controllers or you call this method while your app is launching, the array will be empty.

rmp
  • 3,503
  • 1
  • 17
  • 26
  • Thanks for the suggestion, but no dice. – Geoff H Nov 10 '15 at 20:13
  • That should work, as long as you are not calling `controllers()` while the app is launching. I updated my answer to include info from the docs. – rmp Nov 10 '15 at 20:23
1

GCController will generate GCControllerDidConnectNotification notifications for each controller, including those connected to the device prior to launch. If you're not getting notifications for already-connected controllers, confirm the following:

  • Double-check that it is paired and turned on
  • Make sure it is a MFi controller.
Rob Reuss
  • 1,400
  • 10
  • 20