RemoteControlReceivedWithEvent 方法
我正在尝试获取远程控制启动/停止我的应用程序正在播放的某些音频的事件,但 -remoteControlReceivedWithEvent: 没有被调用。我的应用程序有一个选项卡栏,可以在多个视图之间切换(如果这有什么区别的话)。
每个视图的视图控制器都实现了 Apple 文档中关于使用远程控制事件的设置 ( https://developer.apple.com/iphone/library/documentation/EventHandling/Conc eptual/EventHandlingiPhoneOS/RemoteControl/RemoteControl.html#//apple_ref/d oc/uid/TP40009541-CH7-SW1)。我复制了下面的这些内容以供参考。
关于为什么 -remoteControlReceivedWithEvent: 没有被调用的任何想法?我应该在响应者链中的另一个对象上实现它吗?
史蒂夫
- (BOOL) canBecomeFirstResponder
{
return YES;
}
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}
Possible Duplicate:
remoteControlReceivedWithEvent in AVAudio is not being called
I am trying to get remote control events to start/stop some audio my app is playing, but -remoteControlReceivedWithEvent: is not getting called. My app has a tab bar that switches among multiple views, if that makes any difference.
The view controller for each view implements the setup per Apple docs on using remote control events (https://developer.apple.com/iphone/library/documentation/EventHandling/Conc
eptual/EventHandlingiPhoneOS/RemoteControl/RemoteControl.html#//apple_ref/d
oc/uid/TP40009541-CH7-SW1). I have copied those bits below for reference.
Any ideas on why -remoteControlReceivedWithEvent: is not getting called? Should I be implementing it on another object in the responder chain?
steve
- (BOOL) canBecomeFirstResponder
{
return YES;
}
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否将 UIBackgroundModes 音频键添加到 info.plist 中?请参阅文档。
Did you add the UIBackgroundModes audio key to the info.plist? See the docs.