iOS录制屏幕
iOS 录制屏幕
RPScreenRecorder
通过 RPScreenRecorder
来录制屏幕
定义一个 RPScreenRecorder
private var recorder: RPScreenRecorder!
定义开始录制和停止录制方法
func startRecording(success: (()->Void)? = nil, failure: (()->Void)? = nil) {
recorder.startRecording { error in
if let err = error {
print("Error starting recording: \(err.localizedDescription)")
failure?()
} else {
print("Recording started.")
success?()
}
}
}
func stopRecording(success: ((_ controller: RPPreviewViewController)->Void)? = nil, failure: (()->Void)? = nil) {
recorder.stopRecording { previewController, error in
if let err = error {
print("Error stopping recording: \(err.localizedDescription)")
failure?()
} else if let previewController = previewController {
success?(previewController)
}
}
}
结束录制回调中会给一个带 RPPreviewViewController
的参数,它可以让我们预览刚刚录制好的视频
通过实现 RPPreviewViewControllerDelegate
中的 previewControllerDidFinish
方法
self.previewController?.dismiss(animated: true)
弹出预览控制器进行预览和保存等操作