---
title: "stopRecording(handler:)"
framework: replaykit
role: symbol
role_heading: Instance Method
path: "replaykit/rpscreenrecorder/stoprecording(handler:)"
---

# stopRecording(handler:)

Stops the current recording.

## Declaration

```swift
func stopRecording(handler: ((RPPreviewViewController?, (any Error)?) -> Void)? = nil)
```

## Parameters

- `handler`: A block that is called when the request completes.

## Discussion

Discussion When recording stops with no associated error, present the resulting preview view controller using present(_:animated:completion:). The user will see the built-in preview view controller with options to trim, cut, and share the recording. On iPad, you must present the preview view controller as a popover. Listing 1. Presenting the preview view controller on iPad sharedRecorder.stopRecording { previewViewController, error in     guard let _ = error else {         print("\(error?.localizedDescription ?? "Error")")         return     }     if let previewViewController = previewViewController {         if UIDevice.current.userInterfaceIdiom == .pad {             previewViewController.modalPresentationStyle = .popover             previewViewController.popoverPresentationController?.sourceRect = .zero             previewViewController.popoverPresentationController?.sourceView = self.view         }                  self.previewViewController = previewViewController         previewViewController.previewControllerDelegate = self

// Present the view controller.         self.present(previewViewController, animated: true, completion: nil)     } }

## See Also

### Controlling App Recording

- [startRecording(handler:)](replaykit/rpscreenrecorder/startrecording(handler:).md)
- [stopRecording(withOutput:completionHandler:)](replaykit/rpscreenrecorder/stoprecording(withoutput:completionhandler:).md)
- [startCapture(handler:completionHandler:)](replaykit/rpscreenrecorder/startcapture(handler:completionhandler:).md)
- [RPSampleBufferType](replaykit/rpsamplebuffertype.md)
- [stopCapture(handler:)](replaykit/rpscreenrecorder/stopcapture(handler:).md)
- [discardRecording(handler:)](replaykit/rpscreenrecorder/discardrecording(handler:).md)
- [startRecording(withMicrophoneEnabled:handler:)](replaykit/rpscreenrecorder/startrecording(withmicrophoneenabled:handler:).md)
