objective-ctvossiri-remote

Overriding Siri Remote Menu Button


Okay, so I am making a game for tvOS, and I've overridden the menu button. Basically, if you are in the game and press the menu button, you'll be taken to the main menu. If you are at the main menu and press the menu button, you'll return to the Apple TV home screen.

Here's the code to do that:

- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
{
    UIPress* p = [presses anyObject];

    switch (p.type) {
        case UIPressTypeMenu:

            NSLog(@"Test");

            if(self.gamestate == kGameStateMainMenu)
            {
                [super pressesBegan:presses withEvent:event];
            }
            else if(self.gamestate == kGameStateResetting)
            {

            }
            else
            {
                self.gamestate = kGameStateResetting;
                [self quitGame];
            }

            break;

        default:
            break;
    }
}

This works properly, but there's one issue: if you exit to the apple TV home screen and go back into the app (without quitting it), then no matter what, pressing the menu button will take you back to the apple TV home screen.

Even stranger, the method above is called, and it will even run the quitGame method. It does not call the [super pressesBegan:presses withEvent:event], at least not in the above method, but it still takes the user to the home screen.

Is this a bug, or am I missing something?


Solution

  • You can't only override pressesBegan - you must also override pressesEnded; otherwise it's firing and calling the parent's default behaviour to back out of your app.