Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS remoteControlReceivedWithEvent not called

Tags:

ios

iphone

In the .plist I have added the normal: http://tinyurl.com/c7e9joy And when the iPhone is locked or I'm outside the app and open the remote buttons, I can see the app logo and title there, but they don't react. (I'm testing on my own iPhone.)

// Makes sure we are able to connect to the media buttons on the lock screen.
- (BOOL) canBecomeFirstResponder
{
return YES;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}

- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
NSLog(@"REMOTE");
if (receivedEvent.type == UIEventTypeRemoteControl) {

    switch (receivedEvent.subtype) {

        case UIEventSubtypeRemoteControlTogglePlayPause:
            [self playBtnPressed:nil];

            break;

        case UIEventSubtypeRemoteControlPreviousTrack:
            [self skipTrack:nil];
            break;

        case UIEventSubtypeRemoteControlNextTrack:
            [self skipTrack:nil];
            break;

        default:
            break;
    }
}
}
like image 976
Miko Avatar asked Jan 28 '26 12:01

Miko


1 Answers

You are unregistering for the events in viewWillDisapear meaning that anytime that view isn't visible on the phone you wont be registered for the events. I would change where you register and unregister to the viewDidLoad and viewDidUnload hooks.

like image 130
Dave.B Avatar answered Jan 31 '26 02:01

Dave.B