1

这是我开始录制会话的代码。

var recordingDelegate:AVCaptureFileOutputRecordingDelegate? = self
        cameraSession.beginConfiguration()
        self.cameraSession.addOutput(videoFileOutput)
        cameraSession.commitConfiguration()
        let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
        filePath = documentsURL.appendingPathComponent("temp.mp4")


        videoFileOutput.startRecording(toOutputFileURL: filePath, recordingDelegate: recordingDelegate)

这是之后录制视频的代码。

        self.videoFileOutput.stopRecording()
        UISaveVideoAtPathToSavedPhotosAlbum((filePath?.relativePath)!, nil, nil, nil)
        cameraSession.beginConfiguration()
        cameraSession.removeOutput(videoFileOutput)
        cameraSession.commitConfiguration()

这在 xcode 9 出现之前就可以使用,但是现在当我尝试停止我的视频时,它会导致我的应用程序崩溃,并且 xcode 会抛出错误 Thread 8 signal SIGABART 0_abort_with_payload。我的代码与本节的 xcode 8 相比没有变化,但现在它崩溃了。除了此错误代码之外,我找不到此崩溃的原因。我怀疑这与我保存视频的方式有关。我曾尝试更改 appendingPathComponent,但没有任何区别。

4

1 回答 1

0

您必须在 info plist 中填写新的权限字符串 - 其中一些是 Xcode 9 和 iOS 11 的新权限。检查 info plist 中的以下键是否存在:

  • NSPhotoLibraryAddUsageDescription(新的)
  • NSPhotoLibraryUsageDescription
  • NSCameraUsageDescription
  • NSMicrophoneUsageDescription

您可能不需要所有这些 - 但肯定需要其中一些。(我敢打赌,第一个较新的是 Gotcha)

于 2017-12-26T18:59:48.630 回答