我已经编写了这段代码来录制视频,并想将filePath保存到documents目录,该怎么办?

func startRecording() {
    var currentDateTime = NSDate()
    var formatter = NSDateFormatter()
    formatter.dateFormat = "MM-dd-yyyy, hh:mm:ss a"
    var recordingName = formatter.stringFromDate(currentDateTime) + ".mp4"
    var pathArray = [dirPath, recordingName]
    let filePath = NSURL.fileURLWithPathComponents(pathArray)

    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
        videoRecorder = UIImagePickerController()
        videoRecorder.delegate = self
        videoRecorder.sourceType = UIImagePickerControllerSourceType.Camera
        videoRecorder.mediaTypes = [kUTTypeMovie]
        videoRecorder.videoMaximumDuration = 3600.0
        videoRecorder.startVideoCapture()
    }
}

最佳答案

我之前做过,您可以使用NSFileHandle做到这一点

NSFileHandle(forWritingToURL:filePath,错误:无)

这个对我有用。

关于ios - 如何快速将录像保存到文档目录?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31818990/

10-11 17:14