AVCaptureSession

AVCaptureSession is the central coordinator in AVFoundation that connects camera and microphone inputs to outputs like a preview layer, photo capture, movie recording, or real time frame processing.
WHY IT EXISTS Capturing camera and microphone data on iOS involves configuring hardware, negotiating formats, and routing buffers to multiple destinations at once, a preview on screen, a file on disk, a real time filter. AVCaptureSession exists to give developers one coordinating object for that pipeline instead of managing hardware and buffer routing by hand.
THE MENTAL MODEL Treat AVCaptureSession like a mixing console in a recording studio. Inputs, camera and microphone, plug into one side. Outputs, a live monitor, a tape recorder, a real time effects processor, plug into the other. The console's job is purely routing and running the signal chain; it does not itself decide what the camera sees or how a filter works.
HOW IT WORKS You create a session, set a sessionPreset for resolution and quality, and add an AVCaptureDeviceInput wrapping a physical camera or microphone. You then add one or more outputs: AVCaptureVideoPreviewLayer for on screen preview, AVCapturePhotoOutput for stills, AVCaptureMovieFileOutput for recording, or AVCaptureVideoDataOutput for raw sample buffers delivered to a delegate on a chosen dispatch queue. Any change to inputs or outputs while running should be wrapped in beginConfiguration and commitConfiguration so it applies as one atomic update instead of glitching mid frame. Calling startRunning begins the pipeline on a dedicated background thread that the session manages internally.
WHEN IT MATTERS This matters for any custom camera feature beyond the stock camera UI: barcode scanning, live filters, manual focus and exposure, or multi camera capture. The main footgun is calling startRunning on the main thread, which Apple documents as a blocking call that can take real time to negotiate with hardware, freezing the UI if called there. A second footgun is reconfiguring inputs without begin and commitConfiguration, which causes visible frame corruption or a frozen preview for a moment.
ONE CONCRETE EXAMPLE A QR scanning feature adds an AVCaptureMetadataOutput to a running session so a delegate callback fires whenever a code is decoded, alongside a live AVCaptureVideoPreviewLayer. When the user taps a button to switch from the back to the front camera, the developer removes the old AVCaptureDeviceInput and adds a new one inside a beginConfiguration and commitConfiguration block, so the switch happens as one atomic update instead of a visibly torn frame.
Read the original → developer.apple.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.