0

Please help me to refactor this code, it does not work, I have searched in the internet but did not found any solution. I could not refactor it by myself.

This line:

imageOutput.captureStillImageAsynchronously(from: connection) { (sampleBuffer, error) -> Void in

throws this error:

Value of type 'AVCapturePhotoOutput' has no member 'captureStillImageAsynchronously'

  imageOutput.captureStillImageAsynchronously(from: connection) { (sampleBuffer, error) -> Void in
    if (sampleBuffer == nil || error != nil) {
      DispatchQueue.main.async {
        completion(nil, error)
      }
      return
    }

    guard let data = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: sampleBuffer!, previewPhotoSampleBuffer: nil)  else {
      DispatchQueue.main.async {
        completion(nil, StillImageError.noData)
      }
      return
    }

    guard let image = UIImage(data: data) else {
      DispatchQueue.main.async {
        completion(nil, StillImageError.noImage)
      }
      return
    }

    var saver = ImageSaver()

        .onSuccess { image, assetId in

            completion(assetId, nil)

        }
        .onFailure { error in

    }
    saver = saver.save(image, filter:  nil)

  }
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
  • 1
    Error says `AVCapturePhotoOutput` class doesn't has any function named `captureStillImageAsynchronously`. So that you can't call it by `AVCapturePhotoOutput`'s instance. – TheTiger May 04 '18 at 11:31

1 Answers1

1

captureStillImageAsynchronously(from:completionHandler:) is a function of AVCaptureStillImageOutput, not AVCapturePhotoOutput.

Since AVCaptureStillImageOutput is deprecated since iOS 10, you should use AVCapturePhotoOutput instead, like you do in your code. It has a function with the same use case: capturePhoto(with:delegate:).

For more information about the usage of AVCapturePhotoOutput, check out this question.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223