我被困在用Swift 5和Xcode 11在后台播放音频。
启用后台模式并启动AVAudioSession不再有效,当您离开应用程序几秒钟后,应用程序就会继续关闭。
首先,我得到了一个权利变暖,但溪流开始:
Error acquiring assertion: <NSError: 0x2829830f0; domain: RBSAssertionErrorDomain; code: 2; reason: "Required client entitlement is missing"> {
userInfo = {
RBSAssertionAttribute = <RBSLegacyAttribute: 0x1050a9040; requestedReason: MediaPlayback; reason: MediaPlayback; flags: PreventTaskSuspend | PreventTaskThrottleDown | WantsForegroundResourcePriority>;
}在背景上几秒钟之后,它就关闭了:
[ProcessSuspension] Background task expired while holding WebKit ProcessAssertion (isMainThread? 1).如果我保持应用程序打开音频停止无论如何:
[ProcessSuspension] 0x10dfc8848 - ProcessAssertion::processAssertionWasInvalidated()苹果公司每年都喜欢改变这种状况。到目前为止,有人在iOS 13和Xcode 11/Swift 5上做过这个工作吗?
谢谢!
UPDATE:我刚刚发现这个问题只影响通过WebViews播放的音频。我不确定这是iOS 13上的一个bug,还是苹果真的在减少WebViews的多任务处理。所以我改变了我的应用程序,音频现在正在通过AVPlayer播放。背景音频再次工作。
发布于 2019-09-25 06:40:22
您是否将简历播放音频的代码放置在应用程序中?
func applicationDidEnterBackground(_ application: UIApplication) {
do {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [.mixWithOthers, .allowAirPlay])
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print(error)
}
}另外,让音频,空中播放,图片中的图片从你的目标能力。
https://stackoverflow.com/questions/58090326
复制相似问题