I am working on enabling the option for users to save a video from a post in a social media app to their cameral roll. I am trying to use PHPhotoLibrary
to perform the task similarly to how I did the functionality for saving images and gifs. However, when I try to perform the task with the code as is, I get the following errors:
Error Domain=PHPhotosErrorDomain Code=-1 "(null)"
The operation couldn’t be completed. (PHPhotosErrorDomain error -1.)
The implementation is as follows:
Button(action: {
guard let videoURL = URL(string: media.link.absoluteString) else {
print("Invalid video url.")
return
}
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: videoURL)
print("Video URL: \(videoURL)")
}) { (success, error) in
if let error = error {
debugPrint(error)
print(error.localizedDescription)
} else {
print("Video saved to camera roll!")
}
}
}) {
Text("Save Video")
Image(systemName: "square.and.arrow.down")
}
The video URL is successfully fetched dynamically from the post, but there's an issue with storing it locally in the library. What am I missing?