diff --git a/Sources/DualCameraKit/DualCameraError.swift b/Sources/DualCameraKit/DualCameraError.swift index be8c519..ee57227 100644 --- a/Sources/DualCameraKit/DualCameraError.swift +++ b/Sources/DualCameraKit/DualCameraError.swift @@ -75,7 +75,7 @@ public enum DualCameraError: Error, Equatable { case .notImplemented: return "This feature is not yet implemented." case .permissionDenied: - return "Camera permission was denied by the user." + return "Camera permission was denied – if you want to record please try again and accept the ReplayKit permission prompt." case .recordingFailed(let reason): switch reason { case .assetWriterConfigurationFailed: diff --git a/Sources/DualCameraKit/Screen/DualCameraViewModel.swift b/Sources/DualCameraKit/Screen/DualCameraViewModel.swift index bb73d11..1838b1a 100644 --- a/Sources/DualCameraKit/Screen/DualCameraViewModel.swift +++ b/Sources/DualCameraKit/Screen/DualCameraViewModel.swift @@ -103,6 +103,8 @@ public final class DualCameraViewModel { viewState = .capturing do { + // allow for ui updates based on viewState changing + // (e.g., hiding buttons for screenshot-based approach) try await Task.sleep(for: .seconds(0.25)) let image = try await controller.captureCurrentScreen() viewState = .ready diff --git a/Sources/DualCameraKit/VideoRecording/DualCameraReplayKitVideoRecorder.swift b/Sources/DualCameraKit/VideoRecording/DualCameraReplayKitVideoRecorder.swift index 79c1ed4..022c228 100644 --- a/Sources/DualCameraKit/VideoRecording/DualCameraReplayKitVideoRecorder.swift +++ b/Sources/DualCameraKit/VideoRecording/DualCameraReplayKitVideoRecorder.swift @@ -40,9 +40,23 @@ public actor DualCameraReplayKitVideoRecorder: DualCameraVideoRecording { let outputURL = configure(outputURL: config.outputURL) - recorder.startRecording() - state = .active(outputURL: outputURL) - DualCameraLogger.session.debug("📹 Screen recording started with ReplayKit") + try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + recorder.startRecording { error in + if let error = error { + + if let nsError = error as? NSError, nsError.domain == RPRecordingErrorDomain { + continuation.resume(throwing: DualCameraError.permissionDenied) + } else { + continuation.resume(throwing: error) + } + return + } + + self.state = .active(outputURL: outputURL) + DualCameraLogger.session.debug("📱Screen recording started with ReplayKit") + continuation.resume() + } + } } /// Stops an ongoing video recording and returns the URL of the recorded file