5

I have an application that plays music and want to use lockscreen control (play/pause). With NSLog I can see that my app get's the button trigger but not theUIEventSubtypeRemoteControlTogglePlayPause.

Here's a bit of my code:

- (void)viewDidLoad {
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
{
    NSLog(@"REMOTE RECEIVE");
    if (receivedEvent.type == UIEventTypeRemoteControl)
    {
        NSLog(@"received remote event");
        switch (receivedEvent.subtype)
        {
            case UIEventSubtypeRemoteControlTogglePlayPause:
                NSLog(@"toggle button received");
                //[self togglePlayPauseTapped: nil];
                break;
            default:
                break;
        }
    }

I get "REMOTE RECEIVE" and "received remote event" from the NSLog Output but not the line inside ...TogglePlayPause.

Any ideas?

Samkit Jain
  • 2,523
  • 16
  • 33
ASCJU
  • 317
  • 3
  • 14

2 Answers2

9

use the case

UIEventSubtypeRemoteControlPause

UIEventSubtypeRemoteControlPlay

for iOS 7

Shubhank
  • 21,721
  • 8
  • 65
  • 83
0

The accepted answer is not clear.

UIEventSubtypeRemoteControlPlay, UIEventSubtypeRemoteControlPause and UIEventSubtypeRemoteControlStop are called within the user interaction.

UIEventSubtypeRemoteControlTogglePlayPause is called within headset interaction.

Jakub Truhlář
  • 20,070
  • 9
  • 74
  • 84