tvOS - playPause Gesture not working

705 Views Asked by At

PlayPause button is not responding.
Here is my Code that I placed in viewDidLoad method:

playPauseTapGestureRegocnizer = UITapGestureRecognizer(target: self, action: #selector(playPauseTapped))
playPauseTapGestureRegocnizer.allowedPressTypes = [NSNumber(value: UIPressType.playPause.rawValue)]
view.addGestureRecognizer(playPauseTapGestureRegocnizer)

I tried placing it in multiple methods but it does not work.
The weird thing is that when I change playPause with menu it works perfectly with the menu button.

Am I missing something?

1

There are 1 best solutions below

2
On

Swift 4

PlayPause Gesture doesn't work on a real device. Alternative solution is to listen to UIPressesEvent

override func pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?)
{
    for press in presses
    {
        if press.type == UIPress.PressType.playPause
        {
            // handle play pause action
            break
        }
        else
        {
            super.pressesEnded(presses, with: event)
        }
    }
}