请,我需要帮助是问题,我更改语法Swift 3 for swift 4现在我有很多问题来识别我的所有错误。错误它在函数savePhoto的最后一行。,completionHandler:{ _ in
func takePhoto(_ previewLayer: AVCaptureVideoPreviewLayer, location: CLLocation?, completion: (() -> Void)? = nil) {
guard let connection = stillImageOutput?.connection(with: AVMediaType.video) else { return }
connection.videoOrientation = Helper.videoOrientation()
queue.async {
self.stillImageOutput?.captureStillImageAsynchronously(from: connection) {
buffer, error in
guard let buffer = buffer, error == nil && CMSampleBufferIsValid(buffer),
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer),
let image = UIImage(data: imageData)
else {
DispatchQueue.main.async {
completion?()
}
return
}
self.savePhoto(image, location: location, completion: completion)
}
}
}
func savePhoto(_ image: UIImage, location: CLLocation?, completion: (() -> Void)? = nil) {
PHPhotoLibrary.shared().performChanges({
let request = PHAssetChangeRequest.creationRequestForAsset(from: image)
request.creationDate = Date()
request.location = location
}, completionHandler: { _ in
DispatchQueue.main.async {
completion?()
}
})
}
答案 0 :(得分:1)
将其重写为:
}, completionHandler: { (_, _) in
根据documentation,performChanges(_:completionHandler:)
中的完成处理程序接受两个参数,而不仅仅是一个参数。 _ in
,您使用的是仅占用单个参数的占位符。
答案 1 :(得分:0)
正如您可以在错误消息中清楚地看到completionHandler
传递两个参数而不只是一个。
所以你必须写
}, completionHandler: { (_, _) in
但强烈建议您处理结果和潜在错误。忽略错误会导致糟糕的用户体验。