我使用這段代碼:斯威夫特3照片拍攝
func capturePhoto(blockCompletion: @escaping blockCompletionCapturePhoto) {
guard let connectionVideo = self.stillCameraOutput.connection(withMediaType: AVMediaTypeVideo) else {
blockCompletion(nil, nil)
return
}
connectionVideo.videoOrientation = AVCaptureVideoOrientation.orientationFromUIDeviceOrientation(orientation: UIDevice.current.orientation)
self.stillCameraOutput.captureStillImageAsynchronouslyFromConnection(connectionVideo) { (sampleBuffer: CMSampleBuffer!, err: NSError!) -> Void in
if let err = err {
blockCompletion(image: nil, error: err)
}
else {
if let sampleBuffer = sampleBuffer, let dataImage = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer) {
let image = UIImage(data: dataImage)
blockCompletion(image: image, error: nil)
}
else {
blockCompletion(image: nil, error: nil)
}
}
}
}
它在雨燕2.0工作正常,但轉換後它不工作了。 這條線:
self.stillCameraOutput.captureStillImageAsynchronouslyFromConnection(connectionVideo) { (sampleBuffer: CMSampleBuffer!, err: NSError!) -> Void in
是給我下面的錯誤:
Cannot convert value of type '(CMSampleBuffer!, NSError!) -> Void' to expected argument type '((CMSampleBuffer?, Error?) -> Void)!'
我已經嘗試了一些東西,但不能把它解決。 希望有人能幫助我。
我認爲'NSError'得到了重新命名爲'Error'斯威夫特3.只需刪除'NS',它應該沒問題。你是否遷移了你的代碼?如果它沒有捕捉到它會很奇怪。 – Losiowaty