我如何使我的cocoalibspotify应用程序的iOS响应内置的暂停/播放和下一个/上一个控制?
在主视图控制器中,应用程序需要订阅远程控制事件。
- (void)viewDidLoad {
// ...
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
// ...
}
远程控制按钮按下将触发视图控制器上的remoteControlReceivedEvent:
。事件处理方法如下:
- (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;
}
}
}