xcode tvos app exiting issue when overriding menu button

Swick picture Swick · Oct 6, 2015 · Viewed 8k times · Source

I am currently writing a tvOS app. I've been detecting and overriding the menu button with tapRecognizer to switch between storyboards and other functions. My issue is when I am on my home screen and press menu it does not exit the app. Instead it remembers the last function I used when overriding the menu button and performs that function. Any thoughts on how to clear the tapRecognizer? Or a function that will exit the app?

I'm overriding the menu button with

in Storyboard1

tapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(home)];
tapRecognizer.allowedPressTypes = @[[NSNumber numberWithInteger:UIPressTypeMenu]];
[self.view addGestureRecognizer:tapRecognizer];

in my home subroutine I send the user back to my home page storyboard. But from then on the menu button will not exit the app but send me back to storyboard1. thanks, SW

Answer

ehynds picture ehynds · Oct 9, 2015

Instead of using your own gesture recognizer, override pressesBegan:

override func pressesBegan(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {
  if(presses.first?.type == UIPressType.Menu) {
    // handle event
  } else {
    // perform default action (in your case, exit)
    super.pressesBegan(presses, withEvent: event)
  }
}