gpt4 book ai didi

iOS:处理远程控制事件,然后将事件转发给音乐应用

转载 作者:行者123 更新时间:2023-11-28 22:31:26 25 4
gpt4 key购买 nike

我想在我的应用程序中处理删除控件事件,但也希望该事件可以在我完成后传递给其他应用程序。

我在 Apple 的远程控制事件文档部分找不到明确的说明: http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/Remote-ControlEvents/Remote-ControlEvents.html#//apple_ref/doc/uid/TP40009541-CH7-SW3

这里说:

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];

在我的事件处理程序方法结束时,期望在我的处理程序完成后,当前正在播放的音乐应用程序(例如内置音乐播放器)将能够接收该事件。但令我惊讶的是,它从来没有。

我在这里错过了什么?

最佳答案

确保调用以下方法开始接收事件。

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

然后在您的应用程序委托(delegate)中,您需要监听事件。

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

关于iOS:处理远程控制事件,然后将事件转发给音乐应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17325438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com