<!--
{
  "availability" : [
    "iOS: 9.0.0 - 27.0.0",
    "iPadOS: 9.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 11.0.0 - 27.0.0",
    "tvOS: 10.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "ReplayKit",
  "identifier" : "/documentation/ReplayKit/RPScreenRecorder/stopRecording(handler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "ReplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)RPScreenRecorder(im)stopRecordingWithHandler:"
  },
  "title" : "stopRecording(handler:)"
}
-->

# stopRecording(handler:)

Stops the current recording.

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

## Parameters

`handler`

A block that is called when the request completes.

- `previewViewController`: An instance of the `RPPreviewViewController` class.
- `error`: If an error occurred, this parameter holds an object that explains the error. Otherwise, the value of this parameter is `nil`. See [`RPRecordingErrorCode`](/documentation/ReplayKit/RPRecordingErrorCode) for a list of error codes to ReplayKit.

## Discussion

When recording stops with no associated error, present the resulting preview view controller using <doc://com.apple.documentation/documentation/UIKit/UIViewController/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

```swift
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)
    }
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)