I have an application where I am using AVCapturePhotoOutput to capture a still image. I do the usual stuff:
- Creating the session (new AVCaptureSession)
- Creating the capture output object
- Check that the session can add outputs
- Add the output if able, abort if not
- Start the session
- Check if the session can add an input
- Add the input if able, abort if not
- Set the sessionPreset to AVCaptureSession.Preset.photo
- Modify the format
- Turn on the torch
- Call capturePhoto on my AVCapturePhotoOutput object.
I have a delegate designated with the following signature:
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
if let data = photo.fileDataRepresentation(), let image = UIImage(data: data) {
I have tried this with an iOS 15.1 and an iOS 14.4 device and it works perfectly fine. I'm able to go into that if let block and retrieve image data and do stuff with it. I just tried this today on an iOS 13.4.1 device and the photo object contains empty information as the debugDescription below shows.
I've attempted to query the other functions of the AVCapturePhoto such as cgImageRepresentation(), pixelBuffer, previewCGImageRepresentation() and all of these have ended up being nil.
I know the camera device isn't broken because I can start a session and the callback below provides a valid sampleBuffer on the same device.
public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
Any idea what could be going on here?