TVOS allowedPressTypes not work with new remote

Hi, I want to check if right part is tapped on the touchpad of the remote, and below is my code:


- (void)viewDidLoad {

[super viewDidLoad];


AVPlayer *avPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:@"http://techslides.com/demos/sample-videos/small.mp4"]];

AVPlayerLayer *avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];


avPlayerLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);

[self.view.layer addSublayer:avPlayerLayer];


UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];

tap.allowedPressTypes = @[@(UIPressTypeRightArrow)];

[self.view addGestureRecognizer:tap];


[avPlayer play];

}


- (void)handleLongPress:(UILongPressGestureRecognizer*)sender {

NSLog(@"hello world");

}


Everything works except the tap gesture. The funny thing is this code works good with the old remote. Also, if I remove the line: "tap.allowedPressTypes...", everything works.


Anyone has the idea what is the correct way to detect right part is tapped of the remote? And why does the code work good with the old remote while not with the new one?


Thank you in advance.

Replies

Im doing pretty close to the same thing you are doing. Using an AVPlayer and catching left and right arrow touches while the movie is playing - not actually clicking the button - but just touching the left or right side of the remote's trackpad. The code you have above is nearly identical to mine with the exception that Im creating the AVPlayer outside of the viewDidLoad method and I load up the touches with:


[tapRecognizer setAllowedPressTypes:@[[NSNumber numberWithInteger:UIPressTypeRightArrow]]];


But your code does the same thing, results in NSNumbers in the allowed press types array. My code works correctly with the latest remote (05/31/2016). Have you tried commenting out the player and seeing if it's doing something to snatch the touches? For a test I disabled User Interaction Enabled for the view the player glomps onto but that made no difference - touches still work fine. For your handler you are using a UILongPressGestureRecognizer where I think you want to be using a UITapGestureRecognizer? That probably wont make a difference until you want to use its value in the handler. Are there any other buttons or controls that might be stealing focus?

It sounds like you're trying to replicate the gesture used in AVPlayerViewController, where clicking on the left or right edges of the remote touch surface will skip back or forward by 10 seconds. That actually isn't possible to do with the UIGestureRecognizer API: if you want that behavior, you should consider using AVPlayerViewController.


When performing that skip forward / skip back interaction, the events you'll receive from the Siri Remote look roughly like this: touches began, presses began (UIPressTypeSelect), presses ended (UIPressTypeSelect), touches ended. But your gesture is trying to listen for UIPressTypeRightArrow, which isn't one of the press types that is generated by that interaction.


The reason it appears to work on the old remote is that pressing the right arrow button on the old remote *does* generate a UIPressTypeRightArrow, so your gesture is firing. Also, like KMacTexas mentioned, you can generate a UIPressTypeRightArrow by touch-tapping (not clicking) on the edge of the Siri Remote.

@justin.voss --


I'd like to use that gesture in an application. You mentioned that this wasn't possible with the UIGestureRecognizerAPI. Is there another API that can be used to implement this type of gesture? I assume it's possible as Apple has implemented it, unless it's with private APIs.


Thanks!