AVCapturePhotoOutput produces empty AVCapturePhoto object in photoOutput

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?

Answered by brad_priddy in 703903022

It appears to have been a one-off with this device acting strange. I tested 3 other devices on similar os versions as the malfunctioning one (iOS 13), 4 devices on some variation of iOS 14 and a couple on iOS 15 without any issues.

bold

Accepted Answer

It appears to have been a one-off with this device acting strange. I tested 3 other devices on similar os versions as the malfunctioning one (iOS 13), 4 devices on some variation of iOS 14 and a couple on iOS 15 without any issues.

AVCapturePhotoOutput produces empty AVCapturePhoto object in photoOutput
 
 
Q