3
@IBAction func clickPicture(_ sender: UIButton) {

       let photoSettings = AVCapturePhotoSettings()
        photoSettings.flashMode = .auto
        photoSettings.isHighResolutionPhotoEnabled = true
        if photoSettings.availablePreviewPhotoPixelFormatTypes.count > 0 {
            photoSettings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String : photoSettings.availablePreviewPhotoPixelFormatTypes.first!]
        }

        self.wideAngleOutPut.capturePhoto(with: photoSettings, delegate: self)
    }

When i am calling above function to capture image app throwing exception on line: self.wideAngleOutPut.capturePhoto(with: photoSettings, delegate: self)

In log section I can see the error in more details and its like:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* **-[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] If you specify a non-nil format dictionary in your settings, your delegate must respond to the selector****

Can anybody help with this? Thanks in advance.

1 Answer 1

2

You need to implement the following in your delegate if you set the previewPhotoFormat.

func capture(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?)

I'm guessing this is because this is the only way to access the preview in this situation.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.