-
Build a great camera experience for iPhone Duo
Discover how to leverage the outer and inner cameras on iPhone Duo. Explore the Virtual Front Camera, and find out how to use the direction coordinator to switch between cameras and update your UI as people open and close iPhone Duo. Learn best practices for handling preview aspect ratios, positioning, and rotation to deliver a seamless capture experience.
Chapters
- 0:00 - Introduction
- 0:31 - Meet the new front cameras
- 0:58 - Discover the virtual front camera
- 1:53 - Access each camera individually
- 2:46 - Track camera direction
- 4:03 - Create a direction coordinator
- 4:50 - Use both displays at once
- 5:38 - Work with device descriptors
- 6:17 - Handle a direction change
- 7:03 - Polish your camera preview
- 8:03 - Handle rotation
- 8:47 - Next steps
Resources
Related Videos
Tech Talks
WWDC26
-
Search this video…
Hi, my name is Tarun, and I'm from the camera software team.
In this video, I'll cover the new camera features on iPhone Duo, and I'll go over how to build a great experience with them.
I'll begin by introducing the new front cameras on iPhone Duo.
Then I'll share how to handle camera direction changes when people open or close their device. Finally, I'll cover some tips that will polish your app's camera preview on iPhone Duo.
Now, it's time to meet the iPhone Duo's new front cameras. iPhone Duo is the first iPhone to support two front cameras.
Both of these cameras are square sensors with an ultrawide field of view. On the outside of the device, you'll find the outer ultrawide camera. It takes fantastic photos and videos. Open the device and you'll find the inner ultrawide camera, the first under-display camera on iPhone.
Your app can stream from the front cameras through AVFoundation. Just like on any other iPhone, use the discovery session AVCaptureDeviceDiscoverySession to find the front camera.
Request position .front, along with the Wide or Ultra Wide device type.
When you do this on iPhone Duo, your app will now discover the new Virtual Front Camera.
The Virtual Front Camera is a new AVCaptureDevice that automatically switches between the outer and inner physical cameras.
When you have your iPhone Duo open, the Virtual Front Camera uses the front camera on the inner display.
When you close your iPhone, the camera will automatically switch to the front camera on the outer display. The Virtual Front Camera uses the most relevant front camera for your app.
The Virtual Front Camera handles the camera switch for you. But you can do even more by responding to camera direction changes.
On iPhone Duo, each front camera has its own AVCaptureDevice type.
Use the built-in outer ultrawide device type to access the front camera on the outer display.
Use the built-in inner ultrawide device type to access the one on the inner display.
When you use these device types, you get access to full capabilities of each camera. The inner ultrawide camera has 1080p video resolution with support up to 60fps. The outer ultrawide camera supports up to 4K resolution and 120fps. When your app uses the virtual front camera, you only have access to features common across both physical cameras. That is a max 1080p resolution and 60fps. It's also important to note that depth is only supported when accessing individual cameras.
When you use individual cameras, your app is responsible for switching between them when someone opens or closes their iPhone Duo. Use the new AVCaptureDeviceDirectionCoordinator API to manage the transition.
For some background, AVCaptureDevice has always provided a fixed position property. On iPhone, that has always been back or front. Both the inner and outer front cameras have the value front. But things get more interesting on iPhone Duo, where displays can face opposite directions. This would mean a front camera is not always looking at you. For example, you could be looking at the inner display, but be streaming from the outer front camera. In this case, a front camera is facing away from you.
And while your app is streaming from the outer front camera, you might close the device. That same camera now swings to directly face you.
If you flip the device while it's open, you can take a selfie with the back cameras. Now your app and the back camera are both directly facing you.
To ensure your app always knows where the cameras are facing, use the direction coordinator. The direction coordinator tells your app where the cameras are and keeps you up to date as that changes.
To create a direction coordinator, you need three things: your app's UIView, the device types you want to monitor, and a change handler.
When your app's UIView is on the outer display, the coordinator will show outer display front cameras as forward-facing, and the rear cameras as backward-facing. When the device is opened, your app's UIView moves to the inner display. Your change handler will be called and will report the outer front and rear cameras as backward-facing cameras, and the inner front camera as forward-facing.
If you flip the device while it's open, you can move a camera app to the outer display.
When this happens, you'll find the rear and outer front camera both become forward-facing devices.
On iPhone Duo, a camera app can use both displays at once. That's great for a group video call, or for showing a child something fun while you take their photo.
In this situation, you will have two different UIViews for each display at the same time.
One for the outer display and one for the inner display.
Create a separate direction coordinator for each view. The outer display's coordinator will report the rear cameras as forward-facing, while the inner display's coordinator will report them as backward-facing. Each coordinator reports positions relative to its own view. Camera apps can enable this using the SceneAccessories API.
Learn how in the video, "Leverage multiple displays and scenes on iPhone Duo." Because the direction coordinator is tied to a view, it is isolated to the main actor.
Keep in mind that your change handler from the direction coordinator should not use AVFoundation APIs directly.
Rather than handing you an AVCaptureDevice, the coordinator provides an AVCaptureDeviceDescriptor.
The device descriptor is a main-actor-safe, sendable representation of an AVCaptureDevice.
It contains all the information needed to create an AVCaptureDevice and can be safely passed to your camera actor.
From there, you can interact with your AVFoundation APIs.
Here's what you should do in your change handler.
As someone opens or closes their device, your change handler will be called to tell your app which camera is now forward-facing.
At this time, reconfigure your AVCaptureSession to keep streaming from the forward-facing camera.
Consider how the new camera direction affects your decision to mirror the preview. When the rear camera is forward-facing, mirror the preview for a natural selfie camera experience. Finally, use the change handler to perform any UI updates while changing cameras. You'll find the direction coordinator in AVKit. More details about the coordinator can be found in the article, "Choosing a Camera by the Direction it Faces" in Apple's Developer Documentation.
Now that we've gone over camera direction changes, I'll go over some tips to give your app a polished preview on iPhone Duo. When you stream using the full field of view of rear camera on inner display, you will have additional display space around your preview. Take advantage of this extra space by offsetting the preview, so you can group controls in the remaining space. Alternatively, you can have the preview fill the display. You have the flexibility to make the decision that's right for your app. Use the videoGravity property on AVCaptureVideoPreviewLayer to determine how to lay out your preview within the layer bounds. Check out the documentation for more details.
When streaming from the ultrawide front cameras, you can fill the display by taking advantage of the square sensor. Use dynamicAspectRatio on AVCaptureDevice to select a landscape aspect ratio on the inner display.
Learn more about the power of the square sensor in the video "Support the Center Stage Front Camera in your iOS app" from WWDC26.
A final note on handling rotation in your app: Adopt the rotation coordinator to ensure your camera preview and photos always remain upright. On iPhone Duo, the rotation coordinator will update when your app moves displays.
Use the coordinator to ensure your app's rotation is applied consistently across displays. Read the article "Supporting Device Rotation in Your Camera App" for more information about using the rotation coordinator.
After adopting the rotation coordinator, disable camera-sensor-orientation compensation to improve performance. This compensation is enabled on all the front cameras on iPhone Duo.
A few next steps. Use the iOS 27.1 SDK to take full advantage of iPhone Duo.
Decide how your app will handle switching cameras when the device opens or closes.
Adopt a direction coordinator if you want to move beyond the virtual front camera. Finally, test your app on iPhone Duo and make sure your camera preview looks great.
I look forward to how your camera app unfolds on iPhone Duo.
-
-
3:00 - Understand AVCaptureDevicePosition
enum AVCaptureDevicePosition: Int { case unspecified case back case front } extension AVCaptureDevice { // ... var position: AVCaptureDevicePosition { get } } -
4:06 - Initialize a direction coordinator
directionCoordinator = AVCaptureDeviceDirectionCoordinator( view: view, deviceTypes: [ .builtInOuterUltraWideCamera, .builtInInnerUltraWideCamera, .builtInDualWideCamera, ], changeHandler: { [weak self] map in self?.updateCameraSession(map) } ) -
7:30 - Configure the video preview layer
class AVCaptureVideoPreviewLayer { // ... var videoGravity: AVLayerVideoGravity { get set } } -
7:51 - Select a dynamic aspect ratio
class AVCaptureDevice { // ... var dynamicAspectRatio: AVCaptureDevice.AspectRatio? { get } } -
8:34 - Disable sensor orientation compensation
// Disable for improved performance class AVCapturePhotoOutput: AVCaptureOutput { // ... var isCameraSensorOrientationCompensationEnabled: Bool { get set } }
-
-
- 0:00 - Introduction
Tarun from the camera software team introduces the new camera features on iPhone Duo: the new front cameras, handling camera direction changes when people open or close the device, and tips for polishing your app's camera preview.
- 0:31 - Meet the new front cameras
iPhone Duo is the first iPhone with two front cameras, both square sensors with an ultrawide field of view. The outer ultrawide camera sits on the outside of the device, while opening it reveals the inner ultrawide camera — the first under-display camera on iPhone.
- 0:58 - Discover the virtual front camera
Stream from the front cameras through AVFoundation, using AVCaptureDeviceDiscoverySession with position .front and the wide or ultrawide device type. On iPhone Duo this discovers the new virtual front camera, which automatically switches between the inner physical camera when open and the outer one when closed, always using the most relevant camera for your app.
- 1:53 - Access each camera individually
Each front camera has its own AVCaptureDevice type — built-in outer ultrawide and built-in inner ultrawide — giving access to each camera's full capabilities. The inner camera supports 1080p up to 60fps, the outer up to 4K and 120fps. The virtual front camera exposes only features common to both, meaning 1080p and 60fps, and depth is supported only when accessing the individual cameras.
- 2:46 - Track camera direction
When using individual cameras, your app is responsible for switching as people open or close the device — use the new AVCaptureDeviceDirectionCoordinator. AVCaptureDevice's position property has always been back or front, and both front cameras report front, but on iPhone Duo the displays can face opposite directions, so a front camera isn't always looking at you. The coordinator keeps your app up to date on where cameras are facing.
- 4:03 - Create a direction coordinator
A direction coordinator needs three things: your app's UIView, the device types to monitor, and a change handler. When your view is on the outer display, outer front cameras report as forward-facing and rear cameras as backward-facing. Opening the device moves your view to the inner display and calls your change handler, which then reports the inner front camera as forward-facing.
- 4:50 - Use both displays at once
A camera app can use both displays simultaneously — useful for a group video call, or for showing a child something fun while photographing them. With a separate UIView per display, create a separate direction coordinator for each, since each reports positions relative to its own view. Camera apps enable this with the SceneAccessories API, covered in "Leverage multiple displays and scenes on iPhone Duo".
- 5:38 - Work with device descriptors
Because the direction coordinator is tied to a view, it's isolated to the main actor, so your change handler shouldn't use AVFoundation APIs directly. Instead of an AVCaptureDevice, the coordinator provides an AVCaptureDeviceDescriptor — a main-actor-safe, sendable representation containing everything needed to create an AVCaptureDevice, which you can safely pass to your camera actor.
- 6:17 - Handle a direction change
When your change handler is called, reconfigure your AVCaptureSession to keep streaming from the forward-facing camera. Consider how the new direction affects mirroring — mirror the preview when the rear camera is forward-facing for a natural selfie experience — and perform any UI updates your app needs. The direction coordinator is found in AVKit.
- 7:03 - Polish your camera preview
Streaming the rear camera's full field of view on the inner display leaves extra space around the preview: offset the preview to group controls in the remaining space, or let it fill the display. Use videoGravity on AVCaptureVideoPreviewLayer to control layout within the layer bounds. When streaming from the ultrawide front cameras, use dynamicAspectRatio on AVCaptureDevice to select a landscape aspect ratio and fill the display.
- 8:03 - Handle rotation
Adopt AVCaptureDeviceRotationCoordinator to keep your camera preview and photos upright. On iPhone Duo it updates when your app moves between displays, so rotation is applied consistently. After adopting it, disable camera sensor orientation compensation — enabled on all iPhone Duo front cameras — to improve performance.
- 8:47 - Next steps
Use the iOS 27.1 SDK to take full advantage of iPhone Duo, decide how your app will handle switching cameras when the device opens or closes, adopt a direction coordinator if you want to move beyond the virtual front camera, and test that your camera preview looks great.