iOS: Handle remote-control events and then relay the events to music apps

旧时模样 提交于 2019-12-11 23:46:36

问题


I'd like to handle remove control events in my app, but also would like the event can be passed on to other apps when I'm done.

I cannot find clear instructions in Apple's Remote Control Events doc section: http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/Remote-ControlEvents/Remote-ControlEvents.html#//apple_ref/doc/uid/TP40009541-CH7-SW3

Here it says:

iOS converts commands into UIEvent objects and delivers the events to an app. The app sends them to the first responder and, if the first responder doesn’t handle them, they travel up the responder chain. For more information about the responder chain, see “The Responder Chain Follows a Specific Delivery Path.”

So I thought I'd place

[[self nextResponder] remoteControlReceivedWithEvent: receivedEvent];

at the end of my event handler method, expecting that after my handler is done, a currently playing music app, e.g., the built-in music player, would be able to receive the event. But to my surprise, it never did.

What am I missing here?


回答1:


Make sure you call the following methods to begin receiving the events.

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

Then in your application delegate you need to listen for the events.

-(void)remoteControlReceivedWithEvent:(UIEvent *)event{
    if (event.type == UIEventTypeRemoteControl){
        switch (event.subtype) {
            case UIEventSubtypeRemoteControlTogglePlayPause:
                break;
            default:
                break;
        }
    }
}


来源:https://stackoverflow.com/questions/17325438/ios-handle-remote-control-events-and-then-relay-the-events-to-music-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!