[HOW TO FIX ⚙️] WKWebView Bug: Audio stops while app is in background or lockscreen mode

Young woman with colored pigtails listening to music in headphones on the street

Apps that use WKWebView to play audio from HTML 5 audio, on iOS 13, the sound stops when the app is not in the foreground, even when Audio background capability is on in Background Modes.

When starting the playback, this assertion is thrown:

Error acquiring assertion: <NSError: 0x282cf67c0; domain: RBSAssertionErrorDomain; code: 2; reason: "Required client entitlement is missing"> {
userInfo = {
  RBSAssertionAttribute = <RBSLegacyAttribute: 0x1592432e0; requestedReason: MediaPlayback; reason: MediaPlayback; flags: PreventTaskSuspend | PreventTaskThrottleDown | WantsForegroundResourcePriority>;
}

And while entering background state the following assertion is thrown and audio suspended:

Can't end BackgroundTask: no background task exists with identifier 13 (0xd), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug. 
[ProcessSuspension] Background task expired while holding WebKit ProcessAssertion (isMainThread? 1).

This was not happening in iOS 12, where the audio plays typically when in the background (no code changes, so it has to be iOS-related).

So, how to fix this annoying audio bug? Great news! Just upgrade your WebView app project to the latest WebViewGold version, which uses the newest technology instead of old APIs and SDKs. This app template is built for the future. There you go:

  • Download the WebViewGold app template for iOS 13+ here.
    Or book our full all-inclusive WeSetupYourWebViewApp service.
  • Done! Just resubmit, and this time the audio plays – even in the background mode or lock screen 🙂

Cheers, and enjoy!