Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent game controller button B from quitting app / navigating back to menu in tvOS

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");
};
like image 675
Bobjt Avatar asked Nov 26 '15 05:11

Bobjt


1 Answers

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,

like image 174
François Pilote Avatar answered Jan 01 '23 10:01

François Pilote