Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

WKWebView can not play audio with webrtc on iOS 18 and iPadOS 18

I am experiencing an issue with my app, which includes a WKWebView used for displaying and playing WebRTC content (audio and video). Everything works fine on macOS, but on iOS 18, while the video is displayed correctly, there is no sound. I am wondering if this could be related to privacy permissions on iOS. Could you please clarify if there are any specific privacy permissions I need to address?

I would like to confirm:

  1. AVAudioSession.sharedInstance().setCategory requires any special configuration for WebRTC audio. Are there any particular settings needed for this? My setting codes are below:
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, policy: .longFormAudio)
  1. Do the JavaScript codes in the HTML file require any special handling to ensure WebRTC audio works properly on iOS?
const audioRender = document.createElement('audio');
audioRender.id = 'xxxid';
audioRender.srcObject = streamSource;
audioRender.autoplay = true;
audioHolder.appendChild(audioRender);
  1. Does WKWebViewConfiguration need any specific parameter adjustments to ensure audio playback in WebRTC works as expected?
let webViewConfiguration = WKWebViewConfiguration()
let contentController = WKUserContentController()
contentController.add(self, name: "xxx")
webViewConfiguration.userContentController = contentController
webViewConfiguration.allowsInlineMediaPlayback = true

I'm facing the exact same problem. The only two ways that i was able to get the sound to work were when the screen was locked and by clicking on the incoming call notification making it fullscreen.

Finally I found the solution to the audio issue with WebRTC in WKWebView on iOS. The key was to add the following line of code:

webViewConfiguration.mediaTypesRequiringUserActionForPlayback = []

This resolved the issue, and now audio plays correctly without requiring user action.

WKWebView can not play audio with webrtc on iOS 18 and iPadOS 18
 
 
Q