Skip to content

Instantly share code, notes, and snippets.

@kboy-silvergym
Last active February 25, 2019 07:32
Show Gist options
  • Save kboy-silvergym/186dc97d2d9a2e6c7c70edc1dbac963a to your computer and use it in GitHub Desktop.
Save kboy-silvergym/186dc97d2d9a2e6c7c70edc1dbac963a to your computer and use it in GitHub Desktop.
Sample code for ReplayKit
import ReplayKit
func startRecording() {
let recorder = RPScreenRecorder.shared()
recorder.isMicrophoneEnabled = true
recorder.startRecording(handler: { error in
if let error = error {
NSLog("Failed start recording: \(error.localizedDescription)")
return
}
NSLog("Start recording")
})
}
func finishRecordingAndShowPreview() {
guard RPScreenRecorder.shared().isRecording else {
return
}
RPScreenRecorder
.shared()
.stopRecording(handler: { [weak self] (previewViewController, error) in
guard let self = self, let previewViewController = previewViewController else {
return
}
if let error = error {
NSLog("Failed stop recording: \(error.localizedDescription)")
return
}
DispatchQueue.main.async {
previewViewController.previewControllerDelegate = self
previewViewController.modalPresentationStyle = .overCurrentContext
self.present(previewViewController, animated: true, completion: nil)
}
})
}
extension ViewController: RPPreviewViewControllerDelegate {
func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
DispatchQueue.main.async {
previewController.dismiss(animated: true, completion: nil)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment