如何将视频剪辑保存到照片库-iOS 8& 9 [英] How to save video clip to Photos gallery - ios 8 & 9
本文介绍了如何将视频剪辑保存到照片库-iOS 8& 9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经解决了将视频剪辑保存到照片库"的问题. 这里的代码如下,但它不起作用. 即使saveVideo返回true,但我打开照片画廊"仍无法获取视频剪辑.
I had work out to save video clip to Photos gallery. Here the code as below, but it not working. Even though the saveVideo return true, but I open Photos gallery can not get the video clip.
文件路径
是本地文档目录上的位置
is the location on local Document directory
func saveVideo(filePath: String) {
UISaveVideoAtPathToSavedPhotosAlbum (filePath, self,"video:didFinishSavingWithError:contextInfo:", nil)
}
func video(filePath: String, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) {
if error == nil {
let ac = UIAlertController(title: "Saved!", message: "Your altered video has been saved to your gallery.", preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
self.presentViewController(ac, animated: true, completion: nil)
} else {
let ac = UIAlertController(title: "Save error", message: error?.localizedDescription, preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
self.presentViewController(ac, animated: true, completion: nil)
}
}
推荐答案
PHPhotoLibrary.sharedPhotoLibrary().performChanges({ () -> Void in
let createAssetRequest: PHAssetChangeRequest = PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(NSURL(string: filePath)!)!
createAssetRequest.placeholderForCreatedAsset
}) { (success, error) -> Void in
if success {
//popup alert success
}
else {
//popup alert unsuccess
}
}
这篇关于如何将视频剪辑保存到照片库-iOS 8& 9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文