下面的片段我用来将视频保存在文档目录中(从 AVCaptureMoviefileOutput 收到的 NSdata)
func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!) {
delegate?.recordingStopped?()
var data = NSData(contentsOfURL: outputFileURL)
let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
let documentsDirectory:AnyObject=paths[0]
let dataPath=documentsDirectory.stringByAppendingPathComponent("/MyFolder")
if (!NSFileManager.defaultManager().fileExistsAtPath(dataPath)) {
NSFileManager.defaultManager() .createDirectoryAtPath(dataPath as String, withIntermediateDirectories: false, attributes: nil, error: nil)
}
var outputPathr = "\(dataPath)/TestproximityRwqxq.mp4"
var success = data!.writeToFile(outputPathr as String, options: nil, error: nil)
}
如果用于其他视频(从 NSbundle 中选择视频并转换为 NSdata),相同的代码在模拟器中工作,但不适用于设备,请帮助
最佳答案
此代码运行良好,我们需要使用最低 iOS 版本 8.4(XCode 6.4) 的设备。版本低于 8.4 的设备无法使用 Swift2 获取文档目录的内容。
关于ios - 使用带有来自设备的 avfoundation 的 swift 将 Capture session 保存在文档目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31936811/