我已经解决了将视频剪辑保存到“照片库”的问题。
这里的代码如下,但它不起作用。
即使saveVideo返回true,但我打开“照片画廊”仍无法获取视频剪辑。
文件路径
是本地文档目录上的位置
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 - 如何将视频剪辑保存到照片库-iOS 8和9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35935095/