私は現在、楽しみのためにカメラアプリケーションを構築しようとしていますが、問題が発生しました。
写真やビデオを撮影するプロセスについて 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デリゲートからオブジェクトを取得し、このデリゲートを呼び出しているビュー コントローラーに戻すにはどうすればよいですか?