我被困在使用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()
Apple乐于每年对此进行更改。到目前为止,有人在iOS 13和Xcode 11 / Swift 5上工作过吗?
谢谢!
您是否在Appdelegate中添加了用于恢复播放音频的代码
func applicationDidEnterBackground(_ application: UIApplication) {
do {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [.mixWithOthers, .allowAirPlay])
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print(error)
}
}
另外还可以从目标功能上进行音频,播放和画中画]