1

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?

Liftoff
  • 24,717
  • 13
  • 66
  • 119
  • What is the gamestate set to in this case? And by no matter what you mean even if you've gone back into playing the game then the menu will take you straight out to home? – Wain Oct 27 '15 at 22:59
  • @Wain I have about 9 different game states, such as `kGameStateSelectCharacter`, `kGameStateInGame`, etc. When this is happening, it is always one of the 7 gamestates that fall into the `else` category above. By "no matter what," I do mean that the game state is not `kGameStateMainMenu`. – Liftoff Oct 28 '15 at 04:58
  • Be careful. My game was rejected by Apple, because I used the menu in a different way as expected by Apple – Stefan Oct 28 '15 at 21:39
  • @Stefan Actually, my game was already accepted in it's current state. I've submitted a bug report though. – Liftoff Oct 28 '15 at 22:14

2 Answers2

4

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.

0

if you exit to the apple TV home screen and go back into the app and pressing yet the menu button will take you back to the apple TV home screen, you've probably overwritten the 'pressesEnded' delegate also recalling its super, remove this super call inside pressesEnded.

Danilo
  • 631
  • 1
  • 9
  • 24