Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override Apple Siri remote Menu Button Default behavior

According to Apple's guidelines, pressing the menu button on tvOS should return you to the previous menu, until you're at the top menu at which point it should return you to the OS menus. My question is, how do I prevent the default behavior of the menu button and stop it from returning to the OS menus, but then reactivate it when the user is at the top menu of my app?

like image 236
mredig Avatar asked Sep 19 '15 03:09

mredig


People also ask

Where is the Menu button on the Siri Remote?

Navigation button: This circular or ring-shaped button sits near the top of the controller, and it's primarily for navigating menus. Clicking the top, bottom, left, and right sides of the ring allow you to navigate up, down, left, and right in menus.

Can new Siri Remote change inputs?

The Siri Remote can't change your TV inputs, so if you regularly switch between HDMI ports, you'll need that old clicker.

How do I change the home button on Apple TV?

Change the TV button setting on Apple TV. Go to Remotes and Devices, select TV Button, then select either Home Screen or Apple TV App.


2 Answers

You can register a tapGestureRecognizer and set allowedPressTypes = UIPressTypeMenu code like so:

UITapGestureRecognizer *tapGestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tapGestureRec.allowedPressTypes = @[@(UIPressTypeMenu)];
[self.view addGestureRecognizer:tapGestureRec];

Then whenever the Siri remotes menu button is pressed your handleTap method will be called, allowing you to add any custom logic you need. Just be aware that blocking the menu button from suspending your application on the root view controller can be a cause for App Store rejection.

You can get more information about detecting gestures here and about pressTypes here.

like image 161
Adnan Aftab Avatar answered Dec 15 '22 15:12

Adnan Aftab


Swift version of @C_X's answer, which worked for me.

let tapGesture = UITapGestureRecognizer(target: self, action: "handleTap:")
tapGesture.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)]
self.view.addGestureRecognizer(tapGesture)

Swift 3 version:

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(MyClass.handleMenuPress(_:)))
tapGesture.allowedPressTypes = [NSNumber(value: UIPressType.menu.rawValue)]
self.view.addGestureRecognizer(tapGesture)
like image 41
Individual11 Avatar answered Dec 15 '22 14:12

Individual11