我在新的iOS 12和Xcode 10中遇到问题。当我开始屏幕录像时,它崩溃并显示以下日志
2018-09-22 08:00:09.459676+0530 Chat story[95207:3292867] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[AVAssetWriter finishWritingWithCompletionHandler:] Cannot call method when status is 0'
在最新版本的Xcode中,它工作正常。
这也是我为此编写的代码
func startRecording(withFileName fileName: String, recordingHandler: @escaping (Error?) -> Void,onCompletion: @escaping (Error?)->Void)
{
self.viewOverlay.show()
screenRecorder.startRecording(withFileName: fileName) { (error) in
recordingHandler(error)
self.recordCompleted = onCompletion
}
}
func stopRecording()
{
screenRecorder.stopRecording { (error) in
self.viewOverlay.hide()
self.recordCompleted?(error)
}
}
在ScreenRecorder.swift上,还有另一种方法称为stopRecording方法。这是该方法
func stopRecording(handler: @escaping (Error?) -> Void)
{
if #available(iOS 11.0, *)
{
RPScreenRecorder.shared().stopCapture
{ (error) in
handler(error)
self.assetWriter.finishWriting
{
print(ReplayFileUtil.fetchAllReplays())
}
}
} else {
// Fallback on earlier versions
}
}