diff --git a/package/ios/CameraView+TakeSnapshot.swift b/package/ios/CameraView+TakeSnapshot.swift index 1d9812167e..3ff66537bf 100644 --- a/package/ios/CameraView+TakeSnapshot.swift +++ b/package/ios/CameraView+TakeSnapshot.swift @@ -30,7 +30,7 @@ extension CameraView { // capture was already aborted (timed out) return } - + self.onCaptureShutter() guard let imageBuffer = CMSampleBufferGetImageBuffer(buffer) else { diff --git a/package/ios/CameraView.swift b/package/ios/CameraView.swift index ea0056a46b..b926fff85c 100644 --- a/package/ios/CameraView.swift +++ b/package/ios/CameraView.swift @@ -329,7 +329,7 @@ public final class CameraView: UIView, CameraSessionDelegate { } onStopped([:]) } - + func onCaptureShutter() { guard let onShutter = onShutter else { return diff --git a/package/ios/Core/CameraSession+Photo.swift b/package/ios/Core/CameraSession+Photo.swift index 5e1a8a2adb..b1a4b1ee22 100644 --- a/package/ios/Core/CameraSession+Photo.swift +++ b/package/ios/Core/CameraSession+Photo.swift @@ -90,7 +90,10 @@ extension CameraSession { let enableShutterSound = options["enableShutterSound"] as? Bool ?? true // Actually do the capture! - photoOutput.capturePhoto(with: photoSettings, delegate: PhotoCaptureDelegate(promise: promise, enableShutterSound: enableShutterSound)) + let photoCaptureDelegate = PhotoCaptureDelegate(promise: promise, + enableShutterSound: enableShutterSound, + cameraSessionDelegate: self.delegate) + photoOutput.capturePhoto(with: photoSettings, delegate: photoCaptureDelegate) // Assume that `takePhoto` is always called with the same parameters, so prepare the next call too. photoOutput.setPreparedPhotoSettingsArray([photoSettings], completionHandler: nil) diff --git a/package/ios/Core/PhotoCaptureDelegate.swift b/package/ios/Core/PhotoCaptureDelegate.swift index 54806f7fb0..273030748c 100644 --- a/package/ios/Core/PhotoCaptureDelegate.swift +++ b/package/ios/Core/PhotoCaptureDelegate.swift @@ -16,9 +16,9 @@ private var delegatesReferences: [NSObject] = [] class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate { private let promise: Promise private let enableShutterSound: Bool - private let cameraSessionDelegate: CameraSessionDelegate + private let cameraSessionDelegate: CameraSessionDelegate? - required init(promise: Promise, enableShutterSound: Bool, cameraSessionDelegate: CameraSessionDelegate) { + required init(promise: Promise, enableShutterSound: Bool, cameraSessionDelegate: CameraSessionDelegate?) { self.promise = promise self.enableShutterSound = enableShutterSound self.cameraSessionDelegate = cameraSessionDelegate @@ -31,9 +31,9 @@ class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate { // disable system shutter sound (see https://stackoverflow.com/a/55235949/5281431) AudioServicesDisposeSystemSoundID(1108) } - + // onShutter() event - cameraSessionDelegate.onCaptureShutter() + cameraSessionDelegate?.onCaptureShutter() } func photoOutput(_: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {