Pregunta

How can I make my cocoalibspotify app for iOS respond to the built-in pause/play and next/previous controls? I see no documentation of this.

¿Fue útil?

Solución

In the main view controller, the app needs to subscribe to remote control events.

- (void)viewDidLoad {
    // ...
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    // ...
}

Remote control button presses will then trigger remoteControlReceivedEvent: on your view controller. The event can be handled as follows.

- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
    if (receivedEvent.type == UIEventTypeRemoteControl) {
        switch (receivedEvent.subtype) {                
            case UIEventSubtypeRemoteControlPause:
                // Handle pause
                break;
            case UIEventSubtypeRemoteControlPlay:
                // Handle play
                break;
            case UIEventSubtypeRemoteControlPreviousTrack:
                // Handle Previous
                break;
            case UIEventSubtypeRemoteControlNextTrack:
                // Handle Next
                break;
            default:
                break;
        }
    }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top