我在应用程序中使用ReplayKit来记录可见的屏幕以及一些文本和视频播放。我面临的问题是ReplayKit对于第一次屏幕录制工作正常,但是如果我要在同一会话中再次录制(即不关闭应用程序),则会遇到此错误:
MyViewController[423:39346] viewServiceDidTerminateWithError:: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted}
在这种情况下,我实际上试图在同一ViewController上进行屏幕录像(仅在播放不同的视频并且更改了某些文本内容的情况下)。下面是我的录制代码:
@objc func startRecording() {
let recorder = RPScreenRecorder.shared()
recorder.startRecording{ [unowned self] (error) in
if let unwrappedError = error {
print(unwrappedError.localizedDescription)
print("NOT Recording")
} else {
self.video.play()
print("Recording")
self.isRecording = true
}
}
recordIcon.isHidden = true
ring.isHidden = true
}
@objc func stopRecording() {
let recorder = RPScreenRecorder.shared()
recorder.stopRecording( handler: { previewViewController, error in
if let error = error {
print("\(error.localizedDescription)")
}
// Handling iPads
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)
})
isRecording = false
recordIcon.isHidden = false
ring.isHidden = false
return
}
func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
dismiss(animated: true)
}
对此表示任何帮助,我们将不胜感激。我不想强迫用户在重新录制之前必须重新打开该应用程序。
答案 0 :(得分:0)
可能是您的应用使屏幕录制时间超出了应有的时间。在这种情况下,请尝试实现discardRecording(handler: @escaping () -> Void)
函数。这是有关discardRecording的更多详细信息。