iOS8、AVPlayer播放背景音乐,remoteControlReceivedWithEvent没有调用

iOS 8, AVPlayer background music playing, remoteControlReceivedWithEvent not called

我想在我的应用程序中播放声音(使用 swift), 在 didFinishLaunchingWithOptions 函数中我写了这个

AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)

我有一个 UIView 用来存放 AVPlayer

我用过:

UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
self.becomeFirstResponder()

remoteControlReceivedWithEvent 函数。当应用程序进入后台时,声音会继续播放,但是当我单击暂停按钮(我们用它来播放和暂停来自应用程序外部的声音)时,remoteControlReceivedWithEvent 永远不会被调用!

怎么了?

在我的项目中: 我在 UITabbarViewController

中调用它
-(BOOL)canBecomeFirstResponder{
    return YES;
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}

确保它可以成为第一响应者。 remoteControlReceivedWithEvent in AVAudio is not being called