• <tfoot id='kbNhX'></tfoot>
    <i id='kbNhX'><tr id='kbNhX'><dt id='kbNhX'><q id='kbNhX'><span id='kbNhX'><b id='kbNhX'><form id='kbNhX'><ins id='kbNhX'></ins><ul id='kbNhX'></ul><sub id='kbNhX'></sub></form><legend id='kbNhX'></legend><bdo id='kbNhX'><pre id='kbNhX'><center id='kbNhX'></center></pre></bdo></b><th id='kbNhX'></th></span></q></dt></tr></i><div id='kbNhX'><tfoot id='kbNhX'></tfoot><dl id='kbNhX'><fieldset id='kbNhX'></fieldset></dl></div>

      <bdo id='kbNhX'></bdo><ul id='kbNhX'></ul>

    <small id='kbNhX'></small><noframes id='kbNhX'>

      <legend id='kbNhX'><style id='kbNhX'><dir id='kbNhX'><q id='kbNhX'></q></dir></style></legend>

        iOS - 未收到 UIEventTypeRemoteControl 事件

        时间:2023-08-31
        <i id='WsWS4'><tr id='WsWS4'><dt id='WsWS4'><q id='WsWS4'><span id='WsWS4'><b id='WsWS4'><form id='WsWS4'><ins id='WsWS4'></ins><ul id='WsWS4'></ul><sub id='WsWS4'></sub></form><legend id='WsWS4'></legend><bdo id='WsWS4'><pre id='WsWS4'><center id='WsWS4'></center></pre></bdo></b><th id='WsWS4'></th></span></q></dt></tr></i><div id='WsWS4'><tfoot id='WsWS4'></tfoot><dl id='WsWS4'><fieldset id='WsWS4'></fieldset></dl></div>

        <small id='WsWS4'></small><noframes id='WsWS4'>

          <tbody id='WsWS4'></tbody>

            • <bdo id='WsWS4'></bdo><ul id='WsWS4'></ul>
              <legend id='WsWS4'><style id='WsWS4'><dir id='WsWS4'><q id='WsWS4'></q></dir></style></legend><tfoot id='WsWS4'></tfoot>
                1. 本文介绍了iOS - 未收到 UIEventTypeRemoteControl 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在 AppDelegate (didFinishLaunching) 中有这个:

                  I have this in the AppDelegate (didFinishLaunching):

                  [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
                  

                  我尝试在相关视图控制器中处理事件,但结果参差不齐(一些视图控制器会收到事件,而另一些则不会,即使他们是第一响应者).我尝试子类化 UIApplication.那没有用.现在我正在尝试继承 UIWindow 并执行此操作(请参阅评论):

                  I tried handling the events in the relevant view controllers but that was spotty (some view controllers would get the events and others wouldn't, even when they were first responders). I tried subclassing UIApplication. That didn't work. Now I'm trying to subclass UIWindow and do this (see the comments):

                  - (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;
                      }
                  }
                  }
                  

                  我已经在 info plist 中尝试过使用和不使用它:

                  I have tried both with and without this in the info plist:

                  <key>UIBackgroundModes</key>
                  <array>
                          <string>audio</string>
                  </array>
                  

                  没有区别.正如 Apple 文档所述,您可以使用音频控件模拟远程控制事件(双击主页按钮并在底部滚动到它们).当我按下播放或暂停时,它只会播放我的 iTunes 资料库中的音频.我也试过苹果耳机上的按钮.什么都没有.

                  Doesn't make a difference. As the Apple docs state, you can simulate remote control events with the audio controls (double tap home button and scroll to them on the bottom). When I press play or pause, it just plays audio from my iTunes library. I have tried the buttons on the Apple headphones as well. Nothing.

                  我想要做的就是检测遥控器上的播放/暂停按钮,并处理该事件.我还需要做什么才能捕捉到这些事件?

                  All I want to do is detect the play/pause button on a remote control, and handle the event. What else do I need to do to catch these events?

                  推荐答案

                  好吧,我的生命中还有几个小时进入苹果的黑洞.事实证明,您只能在使用 AVAudioPlayer 播放某种音频或播放有音频的视频文件后才能捕获远程控制事件.这在这里的任何地方都没有记录.

                  ok, a few more hours of my life into black hole of Apple. Turns out that you can only capture remote control events after you have played audio of some kind using the AVAudioPlayer, or if you play a video file that has audio. This is not documented anywhere here.

                  因此,在我尝试捕获远程控制事件之前,我必须先播放一个虚拟静音音频文件.希望这可以帮助某人.

                  So in my case I have to play a dummy silent audio file first before I try to capture remote control events. Hope this helps someone down the line.

                  (更新)请注意,更新的文档现在声明如下:

                  (Update) Please note that the updated documentation now states the following:

                  要接收远程控制事件,您的应用必须做三件事:

                  To receive remote control events, your app must do three things:

                  • 成为第一响应者.呈现多媒体内容的视图或视图控制器必须是第一响应者.
                  • 开启远程控制事件的传递.您的应用必须明确请求开始接收远程控制事件.
                  • 开始播放音频.您的应用必须是正在播放"应用.重申,即使您的应用是第一响应者并且您已转身在事件传递时,您的应用不会接收远程控制事件直到它开始播放音频.
                  • Be the first responder. The view or view controller that presents the multimedia content must be the first responder.
                  • Turn on the delivery of remote control events. Your app must explicitly request to begin receiving remote control events.
                  • Begin playing audio. Your app must be the "Now Playing" app. Restated, even if your app is the first responder and you have turned on event delivery, your app does not receive remote control events until it begins playing audio.

                  这篇关于iOS - 未收到 UIEventTypeRemoteControl 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:MapView 中的 OnTouch 仅在第一次触发 下一篇:Android:为 ListView 中的每个项目添加事件侦听器

                  相关文章

                  最新文章

                  <tfoot id='Jpeyw'></tfoot>

                  • <bdo id='Jpeyw'></bdo><ul id='Jpeyw'></ul>

                  <small id='Jpeyw'></small><noframes id='Jpeyw'>

                    1. <legend id='Jpeyw'><style id='Jpeyw'><dir id='Jpeyw'><q id='Jpeyw'></q></dir></style></legend>
                      <i id='Jpeyw'><tr id='Jpeyw'><dt id='Jpeyw'><q id='Jpeyw'><span id='Jpeyw'><b id='Jpeyw'><form id='Jpeyw'><ins id='Jpeyw'></ins><ul id='Jpeyw'></ul><sub id='Jpeyw'></sub></form><legend id='Jpeyw'></legend><bdo id='Jpeyw'><pre id='Jpeyw'><center id='Jpeyw'></center></pre></bdo></b><th id='Jpeyw'></th></span></q></dt></tr></i><div id='Jpeyw'><tfoot id='Jpeyw'></tfoot><dl id='Jpeyw'><fieldset id='Jpeyw'></fieldset></dl></div>