Bobjt
Bobjt

Reputation: 4100

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");
};

Upvotes: 5

Views: 2302

Answers (2)

Alexander Seeck
Alexander Seeck

Reputation: 39

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.

Upvotes: 0

Fran&#231;ois Pilote
Fran&#231;ois Pilote

Reputation: 368

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,

Upvotes: 5

Related Questions