Contents

stopRecording(handler:)

Stops the current recording.

Declaration

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 for a list of error codes to ReplayKit.

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