iOS:处理远程控制事件,然后将事件中继到音乐应用 [英] iOS: Handle remote-control events and then relay the events to music apps
问题描述
我想处理我应用程序中的删除控制事件,但也希望事件完成后可以将事件传递给其他应用程序.
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
在这里说:
iOS将命令转换为UIEvent对象,并将事件传递给 一个应用程序.该应用会将其发送给第一响应者,如果是第一响应者 响应者不处理它们,它们沿着响应者链上行.为了 有关响应者链的更多信息,请参阅响应者链". 遵循特定的传递路径."
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."
所以我以为我会放置
[[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.
我在这里想念什么?
推荐答案
确保您调用以下方法来开始接收事件.
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;
}
}
}
这篇关于iOS:处理远程控制事件,然后将事件中继到音乐应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!