我目前正在尝试构建一个有趣的相机应用程序并遇到了问题。
我正在使用 Apple 为您提供的拍摄照片或视频过程的示例。在这里找到:
https://developer.apple.com/library/content/samplecode/AVCam/Introduction/Intro.html
我在使用PhotoCaptureDelegate
. 因此,目前当用户拍照时,它会将其保存到用户照片库中。我想做的是,在它捕捉到我想要存储photoData
照片对象的照片之后。这样我就可以在保存之前将照片显示在另一个视图上作为预览。
这是Apple建议使用的:
func capture(_ captureOutput: AVCapturePhotoOutput, didFinishCaptureForResolvedSettings resolvedSettings: AVCaptureResolvedPhotoSettings, error: Error?) {
if let error = error {
print("Error capturing photo: \(error)")
didFinish()
return
}
guard let photoData = photoData else {
print("No photo data resource")
didFinish()
return
}
PHPhotoLibrary.requestAuthorization { [unowned self] status in
if status == .authorized {
PHPhotoLibrary.shared().performChanges({ [unowned self] in
let creationRequest = PHAssetCreationRequest.forAsset()
creationRequest.addResource(with: .photo, data: photoData, options: nil)
if let livePhotoCompanionMovieURL = self.livePhotoCompanionMovieURL {
let livePhotoCompanionMovieFileResourceOptions = PHAssetResourceCreationOptions()
livePhotoCompanionMovieFileResourceOptions.shouldMoveFile = true
creationRequest.addResource(with: .pairedVideo, fileURL: livePhotoCompanionMovieURL, options: livePhotoCompanionMovieFileResourceOptions)
}
}, completionHandler: { [unowned self] success, error in
if let error = error {
print("Error occurered while saving photo to photo library: \(error)")
}
self.didFinish()
}
)
}
else {
self.didFinish()
}
}
}
我将如何photoData
从我的委托中获取对象并将其传递回我的视图控制器,即调用此委托?