Reputation: 1937
Usually if you want to use AVCapturePhoto you do something like this:
func capturePhoto() {
let photoSettings = AVCapturePhotoSettings()
photoOutput?.capturePhoto(with: photoSettings, delegate: self)
}
Then when the photo is processed, photoOutput
method is called:
internal func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
}
Question:
Is it possible to pass custom data to photoOutput via .capturePhoto
? .metadata
is only accessible on iOS and everytime I set a value with the .value()
method I get
[General] [<AVCapturePhotoSettings 0x600003882080> valueWithUniqueID:inPropertyWithKey:]: lookup of unknown key: 'key'.
Upvotes: 1
Views: 413
Reputation: 10398
I think the best and easiest method is to use some other object as a delegate
for the photo capture and also always create a new delegate instance for each capture action. This way you can pass additional data to the delegate object on init
that you can use in the photoOutput(_:didFinishProcessingPhoto:)
method.
I can highly recommend checking out the AVCam sample project from Apple. There they are doing exactly that.
Upvotes: 2