5

The game controller button B is, by default, quitting the app and navigating back to the tvOS home screen. At first I thought this was intuitive, but quickly realized that's what the Nimbus MENU button (dead middle of the controller) is for, and that I actually want to use button B in-game.

Setting a change handler for button B works, but the app still quits when the button is released.

GCControllerButtonValueChangedHandler buttonBHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
        NSLog(@"B");
};
1
  • By "that's what the Nimbus MENU button is for" I mean, selecting Quit from an in-game menu presented by the game. This is what GCController's controllerPausedHandler is for.
    – Bobjt
    Nov 14, 2016 at 19:41

2 Answers 2

5

I had the same issue.

The solution was to have my main ViewController inherit from GCEventViewController instead of UIViewController.

By default, when using GCEventViewController, the MENU button will not return to the menu. In this case, if you want it to be able to return to the menu with the original behavior you can simply set controllerUserInteractionEnabled to YES.

see the documentation for this class here : https://developer.apple.com/library/tvos/documentation/GameController/Reference/GCEventViewController_Ref/index.html

edit : apple dev forum helpep me fix this issue : https://forums.developer.apple.com/message/57926#57926

hope this helps,

4
  • Checking it out, thanks François, will report back with results!
    – Bobjt
    Nov 27, 2015 at 21:28
  • Will accept this answer soon - apologies I honestly have not came back to this part of the impl. yet!
    – Bobjt
    Jan 18, 2016 at 0:45
  • Thanks François. This works. BUT my new problems after having subclassed GCEventViewController is that MENU button is not behaving as expected (getting swallowed, by default); and, #if os( tvOS ) around the class signature is not compiling such that I can no longer share my View Controller across iOS and tvOS (using Swift; I know this works in Obj-c). Will file new questions for those =)
    – Bobjt
    Jan 26, 2016 at 19:00
  • This doesn't work for me. I'm even setting controllerUserInteractionEnabled to false explicitly on viewDidLoad but the MENU button still sends me back to the previous view controller :/
    – endavid
    Feb 15, 2016 at 22:03
0

I too had the issue, related to Unity, but I think this rather hacky solution can help.

Deriving from GCEventViewController one can override several methods, one of them is:

- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event

returning or handling presses without calling super removes all calls to the internals.

1
  • Thanks. either way you need to subclass GCEventViewController, so I'm not sure this is better than just providing a buttonB handler (for B) and controllerPausedHandler (for MENU). This per Francois' answer.
    – Bobjt
    Nov 14, 2016 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.