ios - 如何将视频剪辑保存到照片库-iOS 8和9

标签 ios save ios9 image-gallery

我已经解决了将视频剪辑保存到“照片库”的问题。
这里的代码如下,但它不起作用。
即使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/

相关文章:

c++ - 使用rapidjson c++保存/加载对象 vector

php - 获取DIV的内容并保存到文件,jQuery/JS或服务器端

ios9 - GameKit 回合制比赛和与服务器错误的通信

ios - 在 Swift 中使用 Glimpse 时指定文档目录作为文件输出 URL

javascript - 我想将 JSON 数据从 javascript 传递到 React Native 中的 Native iOS 模块

html - 将用户输入的数据永久保存到html中

ios - 无法在 iOS 9 上验证应用程序

ios - 来自 PHImageManager 的图像数据不同于保存为 Assets 的图像数据

ios - 我应该在哪里添加和删除 UICollectionViewCell 中的观察者?

ios - 在 iOS 中渲染水彩画