1

-When save video url in gallery -I also set read and write permission.

error : Domain=NSCocoaErrorDomain Code=-1 "(null)" in swift.

private func saveVideoToPhotos(url : URL?) {
        if let url = url, let urlData = NSData(contentsOf: url) {
            let galleryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
    
            let filePath = galleryPath.appending("/videoFileName.mp4")
            print(filePath)
            DispatchQueue.main.async {
                urlData.write(toFile: filePath, atomically: false)
                PHPhotoLibrary.shared().performChanges({
                    PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL:URL(fileURLWithPath: filePath))
                }) {
                    success, error in
                    if success {
                    
                        print("Succesfully Saved")
                    } else {
                        DispatchQueue.main.async {
           
                            print(error.debugDescription)
                            self.popupAlert(title: "Request failed.please try again later!", actionTitles: ["ok"], actionStyle: [.default], action: [{_ in }])
                        }
                        
                    }
                }
            }
        }else{
            DispatchQueue.main.async {
               
                self.popupAlert(title: "Request failed.please try again later!", actionTitles: ["ok"], actionStyle: [.default], action: [{_ in }])
            }
        }
    }
  • Have you correctly set the authorisations in info.plist ? BTW, You don't need to dispatch on main queue. All you call is already executed on the main thread. – Moose Apr 15 '21 at 12:16
  • i give all authorisartions image save but video not save. – Vrushabh Dhameliya Apr 15 '21 at 12:22
  • So you mean still images are correctly saved, but videos are not? That's curious. What I would do first is give a try after removing all dispatch. Uneeded dispatch sometimes do weird things. Tell us then. – Moose Apr 15 '21 at 12:29
  • I do also try without dispatch but still show error and when share this video from url it is a nice work. – Vrushabh Dhameliya Apr 15 '21 at 13:21

0 Answers0