没有收到遥控事件 [英] Not receiving remote control events

查看:124
本文介绍了没有收到遥控事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用锁屏/现在为我的应用播放控件,但我没有收到任何事件。文档使它看起来非常直接,所以当我没有得到任何结果时,我有点惊讶。我的应用程序需要接收远程控制事件,以便在设备上播放音频之外。我试着用NSLog打印出一些确认来试试这个。我是否需要使用文档中未提及的音频或媒体框架?我没有收到任何警告或错误,所以我认为不应该有任何问题...任何关于远程控制事件未注册的原因将非常感谢

I am attempting to use the lock screen/now playing controls for my app but am not receiving any events. The documentation makes it seem pretty straight forward so I was a bit a surprised when I didn't get any results. My app needs to receive the remote control events for purposes outside of playing audio on the device. I tried to test this by just having it print out some confirmation with NSLog. Do I need to be using an audio or media framework that wasn't mentioned in the documentation? I am not receiving any warnings or errors so I don't think there should be any issues with that... Any insight concerning why the remote control events aren't registering would be greatly appreciated

以下是相关代码:

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    //Register for lock screen controls
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];

    //Unregister lock screen controls
    [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
    [self resignFirstResponder];
}

- (BOOL)canBecomeFirstResponder{
    return YES;
}

//Lock screen controls
- (void)remoteControlReceivedWithEvent:(UIEvent *)event{
    NSLog(@"RECEIVED");
    if (event.type == UIEventTypeRemoteControl) {

        switch (event.subtype) {

            case UIEventSubtypeRemoteControlTogglePlayPause:
                NSLog(@"RECEIVED");
                break;

            case UIEventSubtypeRemoteControlPreviousTrack:
                NSLog(@"RECEIVED");
                break;

            case UIEventSubtypeRemoteControlNextTrack:
                NSLog(@"RECEIVED");
                break;

            default:
                break;
        }
    }
}


推荐答案

除了Jojas所提到的,你需要确保你有一个活跃的音频会话。看看[AVAudioSession setActive:withFlags:error:]。

In addition to what Jojas mentioned you need to make sure that you have an active audio session. Look at [AVAudioSession setActive:withFlags:error:].

这篇关于没有收到遥控事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆