背景音乐播放不工作在iOS模拟器

我看到很多关于在后台播放audio的问题。 这些问题通常会问为什么audio在模拟器的背景下播放,但是设备根本不会。

就我而言,这是颠倒过来的。

当我在iPad上testing我的示例应用程序时,它完美地工作。 但是,当我在模拟器中开始testing时,它不会在后台继续播放。

这里是我使用的代码:

NSURL *url = [NSURL URLWithString:firstSong]; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; [audioPlayer setNumberOfLoops:-1]; [audioPlayer setCurrentTime:0]; [[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayback error:nil]; [[AVAudioSession sharedInstance]setDelegate:self]; [[AVAudioSession sharedInstance] setActive:YES error:nil]; [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self becomeFirstResponder]; [audioPlayer play]; 

谁能告诉我为什么这不起作用? 这是一个错误还是什么?

iOS模拟器afaik不支持背景audio。