Michael Ortiz
Michael Ortiz

Reputation: 777

RemoteControlReceivedWithEvent in iOS 7 issue

I am having a hard time trying to figure out why in iOS 7 the remote controls don't work. In iOS 7, in the lock screen or even in the Control Center, the buttons are unresponsive and the funny thing is that it works fine on iOS 6.

Here is the code I use:

- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {

if (receivedEvent.type == UIEventTypeRemoteControl) {

    switch (receivedEvent.subtype) {

        case UIEventSubtypeRemoteControlTogglePlayPause:
             if (player.playbackState == MPMusicPlaybackStatePlaying) {

                 [player pause];
             }
             else {
                 [player play];
             }
            break;
        case UIEventSubtypeRemoteControlPreviousTrack:
            break;

        case UIEventSubtypeRemoteControlNextTrack:
            break;

        default:
            break;
    }
}}

This is where I found the information about how to perform this:

https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/Remote-ControlEvents/Remote-ControlEvents.html

Any ideas why this is happening? It works on iOS 6 but not iOS 7.

Thanks

Upvotes: 4

Views: 2755

Answers (2)

Shahab
Shahab

Reputation: 822

I think its a better solution:

case UIEventSubtypeRemoteControlTogglePlayPause:
case UIEventSubtypeRemoteControlPlay:
case UIEventSubtypeRemoteControlPause:
   if (_paused) {
      [self play:self];
   } else {
      [self pause:self];
   }
   break;

Upvotes: 0

Donelle C Sanders Jr
Donelle C Sanders Jr

Reputation: 146

I ran into this same problem and I ended up removing the case statement UIEventSubtypeRemoteControlTogglePlayPause and added case statements UIEventSubtypeRemoteControlPlay and UIEventSubtypeRemoteControlPause individually. I don't have an good explanation for why this changed.

*UPDATE*

I found that UIEventSubtypeRemoteControlTogglePlayPause is called when the user is using their headset to control the player. Just a FYI.

Upvotes: 9

Related Questions