UISaveVideoAtPathToSavedPhotosAlbum 不保存视频并返回错误 0 中止负载
UISaveVideoAtPathToSavedPhotosAlbum not saving videos and returning error 0 abort with payload
这是我开始录制会话的代码。
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,但没有任何区别。
您必须在信息 plist 中填写新的权限字符串 - 其中一些是 Xcode 9 和 iOS 11 的新权限字符串。
检查您的信息 plist 中是否存在以下键:
NSPhotoLibraryAddUsageDescription
(新)
NSPhotoLibraryUsageDescription
NSCameraUsageDescription
NSMicrophoneUsageDescription
您可能不需要所有这些 - 但肯定需要其中一些。
(我敢打赌第一个较新的是 Gotcha)
这是我开始录制会话的代码。
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,但没有任何区别。
您必须在信息 plist 中填写新的权限字符串 - 其中一些是 Xcode 9 和 iOS 11 的新权限字符串。 检查您的信息 plist 中是否存在以下键:
NSPhotoLibraryAddUsageDescription
(新)NSPhotoLibraryUsageDescription
NSCameraUsageDescription
NSMicrophoneUsageDescription
您可能不需要所有这些 - 但肯定需要其中一些。 (我敢打赌第一个较新的是 Gotcha)