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.
A 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.
Interview question
Why does Apple's documentation warn against calling AVCaptureSession's startRunning method on the main thread?
- a.It silently fails and returns without starting capture
- b.It automatically terminates any session already running on a background thread
- c.It requires the main run loop to decode incoming video frames
- d.It is a blocking call that can take noticeable time to configure hardware, freezing the UI if called thereCorrect
Why? this is the answer
startRunning synchronously negotiates with camera hardware and can take a perceptible amount of time, so running it on the main thread blocks user interaction; it does not fail silently or require the main run loop for frame decoding.
Just read this? Test yourself on what you have been reading.
Read the original → developer.apple.com
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles