RemoteControlReceivedWithEvent 方法

发布于 2024-11-24 21:19:53 字数 1239 浏览 3 评论 0原文

可能的重复:
AVAudio中的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

離人涙 2024-12-01 21:19:53

您是否将 UIBackgroundModes 音频键添加到 info.plist 中?请参阅文档

Did you add the UIBackgroundModes audio key to the info.plist? See the docs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文