Allow Siri Remote Menu button when Play/Pause button is overridden
Asked Answered
L

1

3
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(MainController.tapped(_:)))
tapRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.PlayPause.rawValue)]
self.view.addGestureRecognizer(tapRecognizer)

This code allows me to override the play/pause button and it works correctly. However, now I have to long press the Menu button to return to the Apple TV OS menu.

Is there anyway when the Menu button is pressed, it returns directly to the OS menu while the Play/Pause button keeps doing my current logic? I am afraid if clicking on Menu doesn't return to OS menu, my app could be rejected.

Lactone answered 30/7, 2016 at 2:38 Comment(1)
Your application will be rejected if the Menu button does not return to the Apple TV home screen: Apple TV App not exiting to the home screen from initial view controller when menu button pressed on remote.Mistrust
M
3

To return to the Apple TV home screen you can setup a UITapGestureRecognizer in your viewDidLoad like so:

// Setup Menu Button recognizer
let menuGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.handleMenuGesture(_:)))
menuGesture.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)]
self.view.addGestureRecognizer(menuGesture)

and then in handleMenuGesture you suspend your application:

// MARK: - Handle Siri Remote Menu Button
func handleMenuGesture(tap: UITapGestureRecognizer) {
    print("Menu Gesture")
    UIControl().sendAction(#selector(NSURLSessionTask.suspend), to: UIApplication.sharedApplication(), forEvent: nil)
}

Related: Siri Remote's Menu Button not exiting application when UIButton is focused

Mistrust answered 31/7, 2016 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.