Hello,
I want to save the video file into a specific USER Album named "Cambox Album".
Actually only works into the default Album in recent assets with the true new name nameX.mov.
Below the code for define the PathDirectory :
func getDirectoryPath() -> String {
let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, .userDomainMask, true)
let documentsDirectory = paths[0]
return documentsDirectory
}
with this code below, the video is automatically saved in the default user album.
func downloadVideo(urlVideo : URL! ) {
DispatchQueue.global(qos: .background).async {
if let url = urlVideo, let urlData = NSData(contentsOf: url) {
let galleryPath = self.getDirectoryPath()
let filePath = galleryPath + "/nameX.mov"
DispatchQueue.main.async {
urlData.write(toFile: filePath, atomically: true)
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL:
URL(fileURLWithPath: filePath))
}) {success, error in
if success {
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)
} else {
let alertController = UIAlertController(title: error?.localizedDescription, message: nil, preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "ERROR !", style: .default, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}
}
}
}
}
}
if I replace the line with the name of the album by :
let filePath = galleryPath + "/Cambox Album/nameX.mov" nothing happened, I can't see the video anywhere !
is there anybody who can help me to resolve this issue please ?
Regards