Pressing the Menu Button does not quit the app

When pressing the Menu button on my first screen, the app does not exit.

It occurs after displaying another VC, and coming back to the first one.


I tried to override pressesBegan and pressesEnded to call the 'super'

I can see that the methods are called, but the application does not exit.

I can't remember that this behavior was the same in beta 3.

Any help would be appreciated

PS: I can force the exit by calling exit(0) in the pressesEnded method, but that's not recommended by Apple at all,

so I'm looking for a better way to do that.

Replies

Hi Alx,


I'm having the same issue. Did you find a solution?

thx

Suresh

You need to pass the presses event back up to super for this to work. Something like this:


- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event {

for (UIPress *press in presses) {

/

if (UIPressTypeMenu == press.type) {

[super pressesEnded:presses withEvent:event];

return;

}

}

Take a look at the reply posted in this other thread: https://forums.developer.apple.com/thread/23786

it Hi Coinbump,


Thanks for the reply. I really appreciate it. This method does work, however I use multiple storyboards per activity. My Home screen is storyboard1, then an activity is broken into storyboard2, storyboard3. When I am on my storyboard3 I want to return to my apps home screen. I use the method


- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event {

for (UIPress *press in presses) {

if (UIPressTypeMenu == press.type) {

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(bgmusic) object:nil];

UIStoryboard *settingsStoryboard = [UIStoryboard storyboardWithName:@"Home" bundle:nil];

UIViewController *initialSettingsRAN = [settingsStoryboard instantiateInitialViewController];

initialSettingsRAN.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentViewController:initialSettingsRAN animated:NO completion:NULL];

}

}

}


However after I make it to the home storyboard and use the method from [super pressesEnded:presses withEvent:event]; it takes me back to storyboard3 instead of exiting the app.

So I got the same rejection, but I am at a loss here.


Pressing MENU on my game pops up the Game's top level menu.

What do you want me to do when MENU is then pressed again?

Currently, I go back the game.

Should the second press be ignored?


I have been unable to make my game return to the home screen, my main menu is a AlertViewController.


Bram

Using UIAlertViewController as your main menu is probably going to cause problems for you, I would recommend that you not do that.


What you should do to make sure your app can exit when the Menu button is pressed:


1) If you override pressesEnded:withEvent: anywhere in your app, make sure that in the situations where the Menu button should exit the app that you call super. So, when your at your main menu, either don't override that method or make sure that you call super. In other situations, when you don't want the app to exit, don't call super.


2) If you're using gesture recognizers to listen for the Menu button, make sure they are either removed or disabled when you want the Menu button to exit the app. If a gesture recognizer begins to recognize, it will cancel the press, so pressesEnded:withEvent: won't be called at all, which will prevent the app from exiting (canclled presses are delivered to pressesCancelled:withEvent:).

Thanks,


>Using UIAlertViewController as your main menu is probably going to cause problems for you, I would recommend that you not do that.


Indeed.


I've removed the AlertView, and am now using my own OpenGL based menu instead.

I resubmitted my binary last night, but it looks I need to redo it, as I forgot to make my OpenGL based menu also react to MFi input.


That was the nice thing about an AlertView: it already handled all controllers, extended, or Siri Remote, with dpad, l-stick, swipes, etc.


bram

> That was the nice thing about an AlertView: it already handled all controllers, extended, or Siri Remote, with dpad, l-stick, swipes, etc.


Regular UIKit UIViewControllers handle all that automagically too.