Instance Method

stopRecording(handler:)

Stops the current recording.

Declaration

func stopRecording(handler: ((RPPreviewViewController?, 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 Errors 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( handler: { previewViewController, error in    
    if let error = error {
        print("\(error.localizedDescription)")
    }
    if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad {
        previewViewController?.modalPresentationStyle = UIModalPresentationStyle.popover
        previewViewController?.popoverPresentationController?.sourceRect = CGRect.zero
        previewViewController?.popoverPresentationController?.sourceView = self.view
    }
    if previewViewController != nil {
        self.previewViewController = previewViewController
        previewViewController?.previewControllerDelegate = self
    }
    self.present(previewViewController!, animated: true, completion: nil)
    })
    return
}

See Also

Controlling App Recording