Switch Cameras Across iPhone Duo Displays Without Losing The Shot

Imagine recording a cooking tutorial with the phone closed. You open it to read a larger script, glance at the preview, and discover that the app is filming the wrong side of the device. The shutter button still works. The camera is technically running. The composition is gone.

That is the interesting camera problem on iPhone Duo: deciding which camera should follow the person using a particular display, while respecting the shot they already started.

Apple announced Duo on September 9, with device availability beginning October 23. September 27 update: Xcode 27.1 beta and the dedicated preparation documentation are now available. The Duo-specific APIs discussed here require that beta SDK; this post links to Apple’s integration guidance instead of presenting an uncompiled registration example. The switch policy is ordinary Swift that can be developed independently; its ordering and recording-boundary checks were executed separately.

For the surrounding interface, start with preparing your SwiftUI app for iPhone Duo. This post concentrates on capture ownership and recording behavior.

Choose who owns the switch

Duo’s virtual front camera lets discovery with .front and a wide or ultrawide type switch physical cameras automatically. Its common capabilities reach 1080p at 60 fps. Individual access exposes outer-camera 4K and frame rates up to 120 fps; depth requires individual cameras. These are capability ceilings, not a promise that every combination is available. Apple’s camera Tech Talk explains the tradeoff.

For a profile-photo picker, I would start with the virtual path. The useful feature is a person remaining visible while changing how they hold the phone. Extra camera selection code needs to earn its maintenance cost.

For a creator app advertising a specific recording quality, I would make quality a visible decision before capture. If the chosen workflow needs individual-camera features, it also needs an explicit response when the viewer changes displays. An automatic switch that quietly changes what the quality badge means is difficult to defend.

Write that product decision before adding callbacks:

WorkflowProposed behavior
Profile photoFollow the viewer during preview; preserve the chosen capture moment.
Deliberate video recordingDefer automatic camera replacement until the recording finishes.
Live callFollow the selected participant view through the call’s existing renegotiation path.
Document scanKeep the selected subject camera until the user changes capture intent.

These are suggested policies for different apps, not system guarantees. Deferring a switch cannot guarantee the current camera remains usable after a device transition. If capture becomes unavailable, finish or interrupt visibly and offer recovery.

Direction belongs to a view

Individual cameras can report .front while facing away from a display. AVKit’s AVCaptureDeviceDirectionCoordinator tracks facing relative to a UIView. Its main-actor callback supplies Sendable AVCaptureDeviceDescriptor values that can cross to a camera actor. Two display views need separate coordinators. Apple’s direction-coordinator walkthrough shows how to register the view, device types, and change handler.

Retain a coordinator for the view’s lifetime. Resolve the returned descriptor inside the capture owner, using the current iOS 27.1 declarations and Apple’s example. The installed 27.0 SDK cannot verify those new types. The complete policy below deliberately uses app-defined camera identities, so its ordering and recording behavior can be compiled and tested now.

I would give the main camera view authority to select the recording source. A secondary preview can describe a different viewing direction without becoming another writer to the same capture session. Otherwise, each screen can keep requesting a camera change that reverses the other’s decision.

Preserve ordering across the actor boundary

Apple’s AVCam sample puts capture work in a CaptureService actor because configuring and starting a session can block. Keep that division: the UI interprets an update, and the capture service owns the session, current input, and recording state.

Assign a monotonically increasing revision in the UI owner before forwarding each selection. Include a camera-screen lifetime identifier in a real app, so an update from a dismissed screen cannot reconfigure its replacement. Retain the chosen descriptor with that request; create the device and input within the capture service.

The revision solves a specific problem. Suppose a request for camera A is delayed while a later request for camera B reaches the service. A should no longer replace B when it finally arrives. A revision check makes that rule explicit instead of relying on task scheduling.

An actor also permits other work during suspension, and task cancellation is cooperative. Swift’s concurrency guide describes those guarantees. Canceling an old task is useful cleanup, but the capture service still needs to reject obsolete work. If preparation suspends, recheck both the revision and the recording phase after resuming: a recording could start during that suspension without changing the revision. A previous .apply decision expires at the next suspension. Make the final decision and session replacement in one synchronous actor operation.

Make the recording boundary explicit

Here is a small, framework-independent policy for the deliberate-recording option. Keep one instance inside the capture actor. The cameraID is the app’s stable selection identity; retain the corresponding descriptor separately. These are app-defined types, not new AVFoundation APIs.

struct CameraRequest: Sendable, Equatable {
    let revision: UInt64
    let cameraID: String
}

enum RecordingPhase: Sendable {
    case idle
    case recording
    case finishing
}

enum CameraDecision: Sendable, Equatable {
    case unchanged
    case deferred
    case apply(CameraRequest)
}

struct CameraSwitchPolicy {
    private(set) var selectedCameraID: String
    private(set) var phase: RecordingPhase = .idle
    private var latest: CameraRequest?

    init(selectedCameraID: String) {
        self.selectedCameraID = selectedCameraID
    }

    mutating func receive(_ request: CameraRequest) -> CameraDecision {
        if let latest, request.revision <= latest.revision {
            return .unchanged
        }
        latest = request
        return nextDecision()
    }

    mutating func beginRecording() {
        phase = .recording
    }

    mutating func beginFinishing() {
        phase = .finishing
    }

    mutating func recordingDidFinish() -> CameraDecision {
        phase = .idle
        return nextDecision()
    }

    mutating func didApply(_ request: CameraRequest) {
        selectedCameraID = request.cameraID
    }

    private func nextDecision() -> CameraDecision {
        guard let latest, latest.cameraID != selectedCameraID else {
            return .unchanged
        }
        switch phase {
        case .idle: return .apply(latest)
        case .recording, .finishing: return .deferred
        }
    }
}

Process a returned decision immediately in the same actor operation. Enter .recording when accepting a start request, so the startup interval is protected too. Enter .finishing before requesting a stop. Only call didApply after replacement succeeds; keep the previous selection on failure.

For AVCaptureMovieFileOutput, stopping and finishing are different events. The didFinishRecordingTo delegate callback reports completion of pending file writes. Forward that result to the capture service, handle success or failure, and then ask the policy for the latest pending switch. Match completion to the active recording’s identity so a delayed callback cannot unlock a newer recording. A custom writer needs its equivalent completion boundary.

Consider the behavior while recording from A: a request for B is deferred, then another request for A replaces it. When recording finishes, the policy returns .unchanged. It does not perform an unnecessary A-to-B-to-A sequence just because two callbacks arrived.

This reducer intentionally does not manage permissions, interruptions, retry timing, or writer errors. Those belong to the surrounding service. It answers one question: whether the latest requested camera may replace the current one at this recording boundary.

Commit the new camera as one operation

Use beginConfiguration() and commitConfiguration() to batch session changes. Keep the replacement path synchronous on the capture actor, with no await inside the transaction.

Prepare the candidate input first. Retain the old input, remove it within the transaction, then check whether the session can accept the replacement. If insertion fails, attempt to restore the old input before committing. If restoration also fails, publish an unavailable state rather than leaving a live-looking preview and enabled shutter.

Treat this as an app operation with a result: requested, applied, deferred, or failed. Update quality labels from the applied configuration. Clear controls whose meaning depended on the old camera, and keep a retry action tied to current intent. A previous success must not overwrite a newer failure banner when its UI notification arrives late.

Monitor the session’s interruption and runtime-error notifications, too. The policy can choose to defer a switch, but it cannot prevent hardware or session availability from changing.

Check the saved result, then add the second screen

Rotation and mirroring deserve separate acceptance checks. AVCaptureDevice.RotationCoordinator provides distinct angles for capture and preview. Apply the appropriate value to each path; a convincing viewfinder does not prove the exported clip is upright.

Use a scene containing readable text and an asymmetric object. Compare preview, saved file, and the editor after a switch. Decide deliberately whether the recorded image should match a mirrored selfie preview. Also check that an overlay attached to the old camera disappears before the new image is actionable.

A useful Duo enhancement is a subject-facing recording light or countdown. Apple’s CameraCaptureAccessory demonstration places supplementary UI on the outer display while a full-screen camera app runs on the inner display with an active camera session. Availability is dynamic; the accessory’s availability callback lets the app reflect that state.

I would share committed recording state with that accessory. Show a countdown only when capture accepts it, and show the recording indicator only for the active recording. The secondary screen can help a person trust the camera without acquiring authority to change its source.

Before release, exercise three sequences repeatedly: change displays during preview, request several switches during recording, and close the camera screen while a request is pending. Add an interrupted capture and a failed replacement. Each should leave a clear answer to what is being captured, which quality is active, and what the next shutter press will do.