我有一个UIWebView从URL加载m3u:

NSString *url = @"http://141.217.20.38:8000/live.m3u";
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];

其次是:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];

这可以在模拟器上使用,但是当我通过Xcode(带有开发配置文件)将其安装在设备(iPhone 5)上时,音频不会在后台播放。

我不确定我错过了什么,但是任何帮助将不胜感激。

最佳答案

因此,看起来还需要创建AVSession。我添加了以下代码,现在它在设备上的工作原理与在模拟器中相同

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL ok;
NSError *setCategoryError = nil;
ok = [audioSession setCategory:AVAudioSessionCategoryPlayback
                         error:&setCategoryError];
if (!ok) {
    NSLog(@"%s setCategoryError=%@", __PRETTY_FUNCTION__, setCategoryError);
}

07-28 13:08