Skip to content

iOS Screen Sharing

Apply in the code

iOS Screen Sharing allows you to publish your screen as a video track. This document explains how to setup screen sharing on iOS.

Broadcasting Modes

iOS supports two broadcasting modes:

In-App screen recording: Publishes the contents of your app only. Broadcast Extension screen recording: Publishes the contents of your screen, on any app. Screen sharing is started by calling navigator.mediaDevices.getDisplayMedia(Map<String, dynamic> constraints). By default, in-app screen recording is used. No extra setup is needed for in-app screen recording.

Broadcast extension screen recording can be accessed by setting the 'deviceId' key to 'broadcast' in constraints. Broadcast extension screen sharing requires extra setup in your iOS project.

Broadcast Extension Quick Setup

Add a new Broadcast Upload Extension, without UI, to your project in XCode. Update the deployment info for your app and broadcast extension to run in iOS 14 or newer. Add your app and broadcast extension to the same app group. Add the app group id value to the app’s Info.plist for the RTCAppGroupIdentifier key. Copy SampleHandler.swift, SampleUploader.swift, SocketConnection.swift, DarwinNotificationCenter.swift and Atomic.swift files from this sample project to your extension. Make sure they are added to the extension’s target. Update appGroupIdentifier in `SampleHandler to return your app group identifier. Add a new Broadcast Extension

Add a Broadcast Upload Extension through File -> New -> Target.

Fill out the required information for your extension and click Finish.

Ensure your app and broadcast extension’s deployment info is set to iOS 14 or newer.

Setup app groups

Add your extension to an app group by going to your extension’s target in the project; in the Signings & Capabilities tab, click the + button in the top left and add App Groups. If you haven’t done so already, add App Groups to your main app as well, ensuring that the App Group identifier is the same for both.

Setup SampleHandler

Copy SampleHandler.swift, SampleUploader.swift, SocketConnection.swift, DarwinNotificationCenter.swift and Atomic.swift files from this sample project to your extension. You may already have a SampleHandler.swift auto-generated by XCode; just overwrite those contents. Update appGroupIdentifier in SampleHandler to return the app group identifier for your extension.

Your broadcast extension is now ready for broadcast through getDisplayMedia.

Reference