If you want to record a tutorial, gameplay walkthrough, or product demo on an iPhone with a live talking-head overlay, iOS immediately puts two system boundaries in your way:
- A normal
AVCaptureVideoPreviewLayerstops rendering the moment the user switches to another app. - A ReplayKit Broadcast Upload Extension runs in a completely separate OS process with strict memory limits and no direct view hierarchy shared with your main app.
When building Reel: Screen Recorder Face Cam (supporting iOS 18.0+ and macOS 15.2+ on the App Store), our core requirement was simple to state and tricky to get right in production: keep your front camera floating over any app on iPhone while ReplayKit captures the screen, the floating FaceCam, app audio, and microphone narration into a single clean recording.
Below are the four architectural pieces that make this workflow reliable instead of flaky.
1. Use AVPictureInPictureVideoCallViewController + AVSampleBufferDisplayLayer (Not a Standard Preview Layer)
Apple's Picture-in-Picture framework was originally built around AVPlayerLayer for pre-recorded video playback. For a live camera feed that stays visible while the user opens Safari, Keynote, or a game, you need the video-call PiP content source backed by an AVSampleBufferDisplayLayer:
import AVFoundation import AVKit import UIKit final class SampleBufferVideoCallView: UIView { override class var layerClass: AnyClass { AVSampleBufferDisplayLayer.self } var sampleBufferDisplayLayer: AVSampleBufferDisplayLayer { layer as! AVSampleBufferDisplayLayer } override init(frame: CGRect) { super.init(frame: frame) sampleBufferDisplayLayer.videoGravity = .resizeAspectFill } required init?(coder: NSCoder) { super.init(coder: coder) sampleBufferDisplayLayer.videoGravity = .resizeAspectFill } } Wiring that layer into AVPictureInPictureController requires pinning the custom view inside an AVPictureInPictureVideoCallViewController and updating preferredContentSize whenever the user changes aspect ratio (e.g., vertical 9:16 portrait vs. 16:9 widescreen):
func makePiPController( sourceView: UIView, aspectRatio: CGFloat ) -> (AVPictureInPictureController, AVPictureInPictureVideoCallViewController, SampleBufferVideoCallView)? { guard AVPictureInPictureController.isPictureInPictureSupported() else { return nil } let callVC = AVPictureInPictureVideoCallViewController() let videoView = SampleBufferVideoCallView() let baseWidth: CGFloat = 360 let height = aspectRatio > 0 ? baseWidth / aspectRatio : baseWidth * (16.0 / 9.0) callVC.preferredContentSize = CGSize(width: baseWidth, height: height) callVC.view.addSubview(videoView) videoView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ videoView.leadingAnchor.constraint(equalTo: callVC.view.leadingAnchor), videoView.trailingAnchor.constraint(equalTo: callVC.view.trailingAnchor), videoView.topAnchor.constraint(equalTo: callVC.view.topAnchor), videoView.bottomAnchor.constraint(equalTo: callVC.view.bottomAnchor), ]) let contentSource = AVPictureInPictureController.ContentSource( activeVideoCallSourceView: sourceView, contentViewController: callVC ) let controller = AVPictureInPictureController(contentSource: contentSource) return (controller, callVC, videoView) } One easy-to-miss lifecycle trap: do not tear down the AVPictureInPictureController when the app receives willResignActive. Automatic PiP transition from inline only completes after the app begins moving to the background—detaching the controller or its source view too early cancels the floating window right when the user swipes home.
2. Synchronize the ReplayKit Broadcast Extension and Host App via Darwin Notifications
Starting a system-wide screen recording happens inside Apple's RPSystemBroadcastPickerView sheet, which launches your Broadcast Upload Extension in a separate process. The host app cannot call methods directly on SampleHandler, and polling UserDefaults on a timer burns wakeups or misses rapid start/stop transitions.
Instead, the extension writes confirmed broadcast state into the shared App Group UserDefaults and immediately posts a lightweight Darwin notification (CFNotificationCenterGetDarwinNotifyCenter()), which wakes the host app's @MainActor observer even if the camera view was momentarily covered by the system picker:
@MainActor final class BroadcastStatus: ObservableObject { struct State: Equatable { var isBroadcasting = false var isRecording = false } @Published private(set) var state = State() private let defaults: UserDefaults init(suiteName: String, notificationName: String) { self.defaults = UserDefaults(suiteName: suiteName) ?? .standard CFNotificationCenterAddObserver( CFNotificationCenterGetDarwinNotifyCenter(), Unmanaged.passUnretained(self).toOpaque(), { _, observer, _, _, _ in guard let observer else { return } let status = Unmanaged<BroadcastStatus>.fromOpaque(observer).takeUnretainedValue() Task { @MainActor in status.refresh() } }, notificationName as CFString, nil, .deliverImmediately ) refresh() } func refresh() { let broadcasting = defaults.bool(forKey: "isBroadcasting") let next = State( isBroadcasting: broadcasting, isRecording: broadcasting && defaults.bool(forKey: "isRecording") ) if state != next { state = next } } } Once BroadcastStatus flips isRecording == true, the host controller does not blindly fire pipController.startPictureInPicture(). It observes \.isPictureInPicturePossible via KVO and gates auto-start on all four invariants:
-
previewMode == .pipand camera preview is enabled -
UIApplication.shared.applicationState == .activeandview.window != nil -
pipController.isPictureInPicturePossible == trueandisPictureInPictureActive == false pipController.canStartPictureInPictureAutomaticallyFromInline = isPipAutoStartEnabled || isRecording
That single guard eliminates the most common AVKit bug in production: calling startPictureInPicture() a few milliseconds before the display layer has received its first valid frame, which silently drops the request.
3. Zero-Waste GPU Previews When Background Effects Are Active
Creators frequently use virtual backgrounds or blur behind their FaceCam, which creates a subtle UX problem in Settings: if you only render the processed frame, the user cannot tell how cleanly the segmentation mask matches the raw camera feed.
Rather than toggling a boolean that stalls the live capture pipeline—or paying double GPU cost on every recording frame—we split out a lazy RawCameraFeed delegate broadcaster with an isWatched check:
- While recording in PiP mode, no settings view is subscribed (
isWatched == false), so the camera manager skips the raw render pass completely. - The moment the user opens the side-by-side comparison card in Settings,
isWatchedbecomestrueand both the raw camera frame and the background-replaced frame render simultaneously without restarting the capture session.
4. Bridging iOS 18+ and macOS 15.2+ (Mac Catalyst + ScreenCaptureKit)
Supporting both mobile creators on iOS 18.0+ and desktop tutorials on macOS 15.2+ (Sequoia and later) means respecting each platform's native capture and overlay model rather than forcing one UI onto both:
| Layer | iOS (18.0+) | macOS (15.2+ Catalyst) |
|---|---|---|
| Screen & System Audio Capture | ReplayKit RPBroadcastSampleHandler extension | ScreenCaptureKit (SCStream) |
| Floating FaceCam Surface | AVPictureInPictureVideoCallViewController + AVSampleBufferDisplayLayer | Dedicated floating PopoutCameraWindow backed by MetalCameraView |
| In-Capture Controls | Clean PiP window (zero chrome in recorded video) | Hover-only toolbar (Record/Stop, Mic & System Audio mute/gain) |
| Orientation / Aspect Ratio | Dynamic preferredContentSize + orientation lock synced to StreamSettings | Live popout window frame resize (baseWidth / aspectRatio) |
Separating platform capture from the shared Metal camera and audio-mixing layer also let us bring our deployment target down to iOS 18.0+ and macOS 15.2+ without splitting the Swift codebase.
Explore the Full Workflow & Browser Tools
If you want to try the floating FaceCam workflow on iPhone, iPad, or Mac, or inspect how it compares to built-in iOS Screen Recording and desktop tools:
- Step-by-step iPhone guide: How to Keep Your Camera On Over Other Apps on iPhone
- Product overview & specs: Reel: Screen Recorder Face Cam (
reel-studio.arte-soft.com) - Comparisons & browser media tools: Screen Recorder Comparisons · Free Zero-Upload Video Tools
- App Store (iOS 18.0+ & macOS 15.2+): Download Reel on the App Store
