我有一个NSURL类型的videoURL变量。

如果我调用println(videoURL),它将返回以下内容:http://files.parsetfss.com/d540f71f-video.mp4
我设置了一个按钮,该按钮应使用此videoURL并将视频保存到用户的相机胶卷中。

我所做的最好的事情是:

UISaveVideoAtPathToSavedPhotosAlbum(videoPath: String!, completionTarget: AnyObject!, completionSelector: Selector, contextInfo: UnsafeMutablePointer<Void>)

尽管我什至不确定这是否行得通,但我不知道如何将videoFile:NSURL转换为videoPath

任何帮助,对此表示赞赏。

编辑:

以下是不成功的:
UISaveVideoAtPathToSavedPhotosAlbum(videoURL.relativePath, self, nil, nil)

最佳答案

AssetsLibrary已弃用

1:导入照片

import Photos

2:使用此代码将视频从url保存到相机库。
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
             PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(nsUrlToYourVideo)
         }) { saved, error in
             if saved {
                 let alertController = UIAlertController(title: "Your video was successfully saved", message: nil, preferredStyle: .Alert)
                 let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
                 alertController.addAction(defaultAction)
                 self.presentViewController(alertController, animated: true, completion: nil)
             }
         }

swift 3& swift 4
PHPhotoLibrary.shared().performChanges({
    PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: urlToYourVideo)
}) { saved, error in
    if saved {
        let alertController = UIAlertController(title: "Your video was successfully saved", message: nil, preferredStyle: .alert)
        let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
        alertController.addAction(defaultAction)
        self.present(alertController, animated: true, completion: nil)
    }
}

10-07 17:33