我有这样的AppDelegate中(didFinishLaunching):iOS的 - 没有收到UIEventTypeRemoteControl事件
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
我试图处理事件相关视图控制器,但那是参差不齐(有些视图控制器将获得的事件和其他即使他们是第一响应者也不会)。我试过UIApplication的子类。这没有用。现在,我想继承一个UIWindow和做到这一点(见注释):
- (void)sendEvent:(UIEvent *)event {
if (event.type == UIEventTypeRemoteControl) {
NSLog(@"I wish this happened"); //this never happens
}
else
{
NSLog(@"some other event"); //this does happen on any other interaction
[super sendEvent:event];
}
}
- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
if (receivedEvent.type == UIEventTypeRemoteControl) {
NSLog(@"got remote event"); // this never happens either
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
{
NSLog(@"handle play/pause");
break;
}
default:
break;
}
}
}
我试图既没有这种在信息的plist:
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
不有所作为。正如Apple文档所述,您可以使用音频控件模拟远程控制事件(双击主页按钮并滚动到底部)。当我按播放或暂停时,它只播放来自我的iTunes资料库的音频。我也尝试了Apple耳机上的按钮。没有。
我想要做的就是检测遥控器上的播放/暂停按钮,并处理事件。我还需要做些什么来抓住这些事件?
这正是我的问题。非常感谢......将永远需要弄清楚。 –
在iOS 6+中不起作用。我在锁定屏幕上看到我的应用正在播放的信息,但仍然没有按暂停/播放的事件。 – openfrog
而且没有意义:如果使用AVAudioPlayer,则没有视图控制器“呈现它”。它是一个播放音频并没有超视图的类。 – openfrog