【发布时间】:2013-11-10 06:56:38
【问题描述】:
我们的应用通过成为远程控制事件的第一响应者来明确阻止使用远程控制的用户表单,例如,iOS7 之前的旧跳板、耳塞。但是,在 iOS7 上,相同的代码无法绕过控制中心的音乐控件。
通过测试,控制中心似乎绕过了所有音乐控制事件,包括 UIEventSubtypeRemoteControlPause 和 UIEventSubtypeRemoteControlPlay,以及 UIEventSubtypeRemoteControlTogglePlayPause。
是控制中心有自己的远程控制协议还是iOS7中拦截远程控制事件的方式发生了变化?
相同的阻塞代码仍然适用于 iOS6 设备。这是我们的工作:
-
在我们的 appDelegate 中添加了一个方法:
(BOOL)canBecomeFirstResponder { 返回是; }
-
在 applicationDidBecomeActive 中调用它:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
// 将自己设置为第一响应者 [自己成为FirstResponder];
-
在 applicationWillResignActive 中调用它
// 关闭远程控制事件传递 [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
// 辞去第一响应者的职务 [自我辞职FirstResponder];
-
终于添加了
(void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {
if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
NSLog(@"Received: UIEventSubtypeRemoteControlTogglePlayPause\n");
break;
case UIEventSubtypeRemoteControlPreviousTrack:
NSLog(@"Received: UIEventSubtypeRemoteControlPreviousTrack\n");
break;
case UIEventSubtypeRemoteControlNextTrack:
NSLog(@"Received: UIEventSubtypeRemoteControlNextTrack\n");
break;
case UIEventSubtypeRemoteControlPlay:
NSLog(@"Received: UIEventSubtypeRemoteControlPlay\n");
break;
case UIEventSubtypeRemoteControlPause:
NSLog(@"Received: UIEventSubtypeRemoteControlPause\n");
break;
case UIEventSubtypeRemoteControlStop:
NSLog(@"Received: UIEventSubtypeRemoteControlStop\n");
break;
default:
NSLog(@"Received: Some remove control events\n");
break;
}
}
}
任何指针将不胜感激。
【问题讨论】:
-
为什么要投票给我?这是一个现实的问题。
标签: ios objective-c appdelegate remote-control control-center